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