Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXTextPortionEnumeration.java
blobe9bec556c25b498405c83385e7d498756b7dc4db
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.text.ControlCharacter;
32 import com.sun.star.text.XText;
33 import com.sun.star.text.XTextCursor;
34 import com.sun.star.text.XTextDocument;
35 import com.sun.star.uno.AnyConverter;
36 import com.sun.star.uno.Type;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
40 /**
42 * initial description
43 * @see com.sun.star.text.TextPortion
46 public class SwXTextPortionEnumeration extends TestCase {
48 XTextDocument xTextDoc;
50 @Override
51 protected void initialize( TestParameters tParam, PrintWriter log ) {
52 SOfficeFactory SOF = SOfficeFactory.getFactory( 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 @Override
65 protected void cleanup( TestParameters tParam, PrintWriter log ) {
66 log.println( " disposing xTextDoc " );
67 util.DesktopTools.closeDoc(xTextDoc);
70 /**
71 * creating a Testenvironment for the interfaces to be tested
73 * @param tParam class which contains additional test parameters
74 * @param log class to log the test state and result
76 * @return Status class
78 * @see TestParameters
79 * @see PrintWriter
81 @Override
82 protected synchronized TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
84 XInterface param = null;
86 // creation of testobject here
87 // first we write what we are intend to do to log file
88 log.println( "creating a test environment" );
90 // create testobject here
92 XText oText = xTextDoc.getText();
93 XTextCursor oCursor = oText.createTextCursor();
95 log.println( "inserting Strings" );
96 log.println( "inserting ControlCharacter" );
99 try{
100 for (int i =0; i < 5; i++){
101 oText.insertString( oCursor,"Paragraph Number: " + i, false);
102 oText.insertControlCharacter(
103 oCursor, ControlCharacter.LINE_BREAK, false );
104 oText.insertString( oCursor,
105 "The quick brown fox jumps over the lazy Dog: SwXParagraph\n",
106 false);
107 oText.insertControlCharacter(
108 oCursor, ControlCharacter.LINE_BREAK, false );
109 oText.insertString( oCursor,
110 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG: SwXParagraph",
111 false);
112 oText.insertControlCharacter(
113 oCursor, ControlCharacter.PARAGRAPH_BREAK, false );
115 }catch(Exception e){
116 log.println("Couldn't insert Text");
117 e.printStackTrace();
118 throw new StatusException( "Couldn't insert Text", e );
121 // Enumeration
122 XEnumerationAccess oEnumA = UnoRuntime.queryInterface( XEnumerationAccess.class, oText );
123 XEnumeration oEnum = oEnumA.createEnumeration();
125 while ( (oEnum.hasMoreElements()) ) {
126 try {
127 param = (XInterface) AnyConverter.toObject(
128 new Type(XInterface.class),oEnum.nextElement());
129 } catch ( Exception e) {
130 log.println("Couldn't get Paragraph");
131 e.printStackTrace();
132 throw new StatusException( "Couldn't get Paragraph", e );
136 XEnumerationAccess oEnumP = UnoRuntime.queryInterface( XEnumerationAccess.class, param );
137 XEnumeration oEnum2 = oEnumP.createEnumeration();
139 log.println( "creating a new environment for TextPortionEnumeration object" );
140 TestEnvironment tEnv = new TestEnvironment( oEnum2 );
142 log.println("adding ObjRelation ENUM for XEnumeration");
143 tEnv.addObjRelation("ENUM", oEnumP);
145 return tEnv;
146 } // finish method getTestEnvironment
149 } // finish class SwXTextPortionEnumeration