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