bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXParagraphEnumeration.java
blobace70b24c369404664d2898a81e65b6c485fccb5
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.UnoRuntime;
37 import com.sun.star.uno.XInterface;
39 /**
40 * Test for object which is represented by service
41 * <code>com.sun.star.text.ParagraphEnumeration</code>. <p>
42 * Object implements the following interfaces :
43 * <ul>
44 * <li> <code>com::sun::star::container::XEnumeration</code></li>
45 * </ul> <p>
46 * This object test <b> is NOT </b> designed to be run in several
47 * threads concurently.
48 * @see com.sun.star.container.XEnumeration
49 * @see ifc.container._XEnumeration
51 public class SwXParagraphEnumeration extends TestCase {
52 XTextDocument xTextDoc = null;
54 /**
55 * Creates text document.
57 protected void initialize( TestParameters tParam, PrintWriter log ) {
58 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
59 try {
60 log.println( "creating a textdocument" );
61 xTextDoc = SOF.createTextDoc( null );
62 } catch ( com.sun.star.uno.Exception e ) {
63 e.printStackTrace( log );
64 throw new StatusException( "Couldn't create document", e );
68 /**
69 * Disposes text document.
71 protected void cleanup( TestParameters tParam, PrintWriter log ) {
72 log.println( " disposing xTextDoc " );
73 util.DesktopTools.closeDoc(xTextDoc);
76 /**
77 * Creating a Testenvironment for the interfaces to be tested. After major
78 * text is gotten from a text document, three paragraphs (each of them
79 * filled by 5 strings) are inserted to major text. Finally, paragraph
80 * enumeration is created using <code>XEnumeration</code> interface.
81 * Object relations created :
82 * <ul>
83 * <li> <code>'ENUM'</code> for
84 * {@link ifc.container._XEnumeration} : major text of text document
85 * with several paragraphs inserted, queried to
86 * <code>XEnumerationAccess</code> interface.</li>
87 * </ul>
89 public synchronized TestEnvironment createTestEnvironment(
90 TestParameters tParam, PrintWriter log ) throws StatusException {
91 XInterface oObj = null;
93 log.println( "creating a test environment" );
94 XText oText = xTextDoc.getText();
95 XTextCursor oCursor = oText.createTextCursor();
97 for (int i=0; i<3; i++) {
98 try {
99 oText.insertString( oCursor, "Paragraph Number: " + i, false);
100 oText.insertControlCharacter( oCursor,
101 ControlCharacter.LINE_BREAK, false );
102 } catch ( com.sun.star.lang.IllegalArgumentException e ){
103 log.println( "EXCEPTION: " + e);
106 for (int j=0; j<5; j++){
107 try {
108 oText.insertString( oCursor,"The quick brown fox jumps"+
109 " over the lazy Dog: SwXParagraph", false);
110 oText.insertControlCharacter( oCursor,
111 ControlCharacter.LINE_BREAK, false );
112 oText.insertString( oCursor, "THE QUICK BROWN FOX JUMPS"+
113 " OVER THE LAZY DOG: SwXParagraph", false);
114 oText.insertControlCharacter( oCursor,
115 ControlCharacter.LINE_BREAK, false );
116 } catch ( com.sun.star.lang.IllegalArgumentException e ){
117 log.println( "EXCEPTION: " + e);
121 try {
122 oText.insertControlCharacter( oCursor,
123 ControlCharacter.PARAGRAPH_BREAK, false );
124 } catch ( com.sun.star.lang.IllegalArgumentException e ){
125 log.println( "EXCEPTION: " + e);
129 // Enumeration
130 XEnumerationAccess oEnumA = UnoRuntime.queryInterface( XEnumerationAccess.class, oText );
131 XEnumeration oEnum = oEnumA.createEnumeration();
133 oObj = oEnum;
135 log.println("creating a new environment for ParagraphEnumeration object");
136 TestEnvironment tEnv = new TestEnvironment( oObj );
138 tEnv.addObjRelation("ENUM", oEnumA);
140 return tEnv;
141 } // finish method getTestEnvironment
143 } // finish class SwXParagraphEnumeration