bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXTextColumns.java
blob7d4746ab1ac3a457fbd6457b0a7d78b6f2018efa
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.XIndexAccess;
31 import com.sun.star.container.XNameAccess;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.style.XStyle;
34 import com.sun.star.style.XStyleFamiliesSupplier;
35 import com.sun.star.text.ControlCharacter;
36 import com.sun.star.text.XText;
37 import com.sun.star.text.XTextColumns;
38 import com.sun.star.text.XTextCursor;
39 import com.sun.star.text.XTextDocument;
40 import com.sun.star.uno.AnyConverter;
41 import com.sun.star.uno.Type;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XInterface;
45 /**
46 * Test for object which is represented by service
47 * <code>com.sun.star.text.TextColumns</code>. <p>
48 * Object implements the following interfaces :
49 * <ul>
50 * <li> <code>com::sun::star::text::XTextColumns</code></li>
51 * <li> <code>com::sun::star::text::TextColumns</code></li>
52 * </ul> <p>
53 * This object test <b> is NOT </b> designed to be run in several
54 * threads concurently.
55 * @see com.sun.star.text.XTextColumns
56 * @see com.sun.star.text.TextColumns
57 * @see ifc.text._XTextColumns
58 * @see ifc.text._TextColumns
60 public class SwXTextColumns extends TestCase {
61 XTextDocument xTextDoc;
63 /**
64 * Creates text document.
66 protected void initialize( TestParameters tParam, PrintWriter log ) {
67 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
68 try {
69 log.println( "creating a textdocument" );
70 xTextDoc = SOF.createTextDoc( null );
71 } catch ( com.sun.star.uno.Exception e ) {
72 e.printStackTrace( log );
73 throw new StatusException( "Couldn't create document", e );
77 /**
78 * Disposes text document.
80 protected void cleanup( TestParameters tParam, PrintWriter log ) {
81 log.println( " disposing xTextDoc " );
82 util.DesktopTools.closeDoc(xTextDoc);
85 /**
86 * Creating a Testenvironment for the interfaces to be tested. After style
87 * families are gotten from text document using
88 * <code>XStyleFamiliesSupplier</code> interface, style family indexed '2'
89 * is obtained using <code>XIndexAccess</code> interface. Then style
90 * named 'Standard' is gotten from previously obtained style family using
91 * <code>XNameAccess</code> interface, and 'TextColumns' property value
92 * of this style is returned as a test component. Finally, several
93 * paragraphs within the text are inserted to a text document.
95 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
96 XInterface oObj = null;
97 TestEnvironment tEnv = null;
98 XStyle oStyle = null;
100 log.println( "creating a test environment" );
101 log.println("getting PageStyle");
102 XStyleFamiliesSupplier oSFS = UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, xTextDoc);
103 XNameAccess oSF = oSFS.getStyleFamilies();
104 XIndexAccess oSFIA = UnoRuntime.queryInterface(XIndexAccess.class, oSF);
106 try {
107 XNameAccess oSFNA = (XNameAccess) AnyConverter.toObject(
108 new Type(XNameAccess.class),oSFIA.getByIndex(2));
109 oStyle = (XStyle) AnyConverter.toObject(
110 new Type(XStyle.class),oSFNA.getByName("Standard"));
111 } catch ( com.sun.star.lang.WrappedTargetException e ) {
112 log.println("Error, exception occurred while getting style.");
113 e.printStackTrace(log);
114 } catch ( com.sun.star.lang.IndexOutOfBoundsException e ) {
115 log.println("Error, exception occurred while getting style.");
116 e.printStackTrace(log);
117 } catch ( com.sun.star.container.NoSuchElementException e ) {
118 log.println("Error, exception occurred while getting style.");
119 e.printStackTrace(log);
120 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
121 log.println("Error, exception occurred while getting style.");
122 e.printStackTrace(log);
125 try {
126 log.println("Getting property ('TextColumns') value of style "
127 + oStyle.getName());
128 XPropertySet xProps = UnoRuntime.queryInterface(XPropertySet.class,oStyle);
129 oObj = (XTextColumns) AnyConverter.toObject(
130 new Type(XTextColumns.class),xProps.getPropertyValue("TextColumns"));
131 } catch ( com.sun.star.lang.WrappedTargetException e ) {
132 log.println("Exception occurred while getting style property");
133 e.printStackTrace(log);
134 } catch ( com.sun.star.beans.UnknownPropertyException e ) {
135 log.println("Exception occurred while getting style property");
136 e.printStackTrace(log);
137 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
138 log.println("Exception occurred while getting style property");
139 e.printStackTrace(log);
142 XText oText = xTextDoc.getText();
143 XTextCursor oCursor = oText.createTextCursor();
145 log.println( "inserting some text to text document..." );
146 try {
147 for (int i =0; i < 5; i++){
148 oText.insertString( oCursor,"Paragraph Number: " + i, false);
149 oText.insertString( oCursor,
150 "The quick brown fox jumps over the lazy Dog: SwXParagraph",
151 false);
152 oText.insertControlCharacter( oCursor,
153 ControlCharacter.PARAGRAPH_BREAK, false );
154 oText.insertString( oCursor,
155 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG: SwXParagraph",
156 false);
157 oText.insertControlCharacter( oCursor,
158 ControlCharacter.PARAGRAPH_BREAK, false );
159 oText.insertControlCharacter( oCursor,
160 ControlCharacter.LINE_BREAK, false );
162 } catch ( com.sun.star.lang.IllegalArgumentException e ){
163 log.println("Exception occurred while inserting Text");
164 e.printStackTrace(log);
167 log.println("creating a new environment for object");
168 tEnv = new TestEnvironment(oObj);
169 return tEnv;
170 } // finish method getTestEnvironment
172 } // finish class SwXTextColumns