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 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
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
.style
.XStyle
;
33 import com
.sun
.star
.style
.XStyleFamiliesSupplier
;
34 import com
.sun
.star
.text
.ControlCharacter
;
35 import com
.sun
.star
.text
.XText
;
36 import com
.sun
.star
.text
.XTextColumns
;
37 import com
.sun
.star
.text
.XTextCursor
;
38 import com
.sun
.star
.text
.XTextDocument
;
39 import com
.sun
.star
.uno
.AnyConverter
;
40 import com
.sun
.star
.uno
.Type
;
41 import com
.sun
.star
.uno
.UnoRuntime
;
42 import com
.sun
.star
.uno
.XInterface
;
45 * Test for object which is represented by service
46 * <code>com.sun.star.text.TextColumns</code>. <p>
47 * Object implements the following interfaces :
49 * <li> <code>com::sun::star::text::XTextColumns</code></li>
50 * <li> <code>com::sun::star::text::TextColumns</code></li>
52 * This object test <b> is NOT </b> designed to be run in several
53 * threads concurently.
54 * @see com.sun.star.text.XTextColumns
55 * @see com.sun.star.text.TextColumns
56 * @see ifc.text._XTextColumns
57 * @see ifc.text._TextColumns
59 public class SwXTextColumns
extends TestCase
{
60 XTextDocument xTextDoc
;
63 * Creates text document.
66 protected void initialize( TestParameters tParam
, PrintWriter log
) {
67 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
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
);
78 * Disposes text document.
81 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
82 log
.println( " disposing xTextDoc " );
83 util
.DesktopTools
.closeDoc(xTextDoc
);
87 * Creating a Testenvironment for the interfaces to be tested. After style
88 * families are gotten from text document using
89 * <code>XStyleFamiliesSupplier</code> interface, style family indexed '2'
90 * is obtained using <code>XIndexAccess</code> interface. Then style
91 * named 'Standard' is gotten from previously obtained style family using
92 * <code>XNameAccess</code> interface, and 'TextColumns' property value
93 * of this style is returned as a test component. Finally, several
94 * paragraphs within the text are inserted to a text document.
97 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
98 XInterface oObj
= null;
99 TestEnvironment tEnv
= null;
100 XStyle oStyle
= null;
102 log
.println( "creating a test environment" );
103 log
.println("getting PageStyle");
104 XStyleFamiliesSupplier oSFS
= UnoRuntime
.queryInterface(XStyleFamiliesSupplier
.class, xTextDoc
);
105 XNameAccess oSF
= oSFS
.getStyleFamilies();
106 XIndexAccess oSFIA
= UnoRuntime
.queryInterface(XIndexAccess
.class, oSF
);
109 XNameAccess oSFNA
= (XNameAccess
) AnyConverter
.toObject(
110 new Type(XNameAccess
.class),oSFIA
.getByIndex(2));
111 oStyle
= (XStyle
) AnyConverter
.toObject(
112 new Type(XStyle
.class),oSFNA
.getByName("Standard"));
113 } catch ( com
.sun
.star
.lang
.WrappedTargetException e
) {
114 log
.println("Error, exception occurred while getting style.");
115 e
.printStackTrace(log
);
116 } catch ( com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
117 log
.println("Error, exception occurred while getting style.");
118 e
.printStackTrace(log
);
119 } catch ( com
.sun
.star
.container
.NoSuchElementException e
) {
120 log
.println("Error, exception occurred while getting style.");
121 e
.printStackTrace(log
);
122 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
123 log
.println("Error, exception occurred while getting style.");
124 e
.printStackTrace(log
);
128 log
.println("Getting property ('TextColumns') value of style "
130 XPropertySet xProps
= UnoRuntime
.queryInterface(XPropertySet
.class,oStyle
);
131 oObj
= (XTextColumns
) AnyConverter
.toObject(
132 new Type(XTextColumns
.class),xProps
.getPropertyValue("TextColumns"));
133 } catch ( com
.sun
.star
.lang
.WrappedTargetException e
) {
134 log
.println("Exception occurred while getting style property");
135 e
.printStackTrace(log
);
136 } catch ( com
.sun
.star
.beans
.UnknownPropertyException e
) {
137 log
.println("Exception occurred while getting style property");
138 e
.printStackTrace(log
);
139 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
140 log
.println("Exception occurred while getting style property");
141 e
.printStackTrace(log
);
144 XText oText
= xTextDoc
.getText();
145 XTextCursor oCursor
= oText
.createTextCursor();
147 log
.println( "inserting some text to text document..." );
149 for (int i
=0; i
< 5; i
++){
150 oText
.insertString( oCursor
,"Paragraph Number: " + i
, false);
151 oText
.insertString( oCursor
,
152 "The quick brown fox jumps over the lazy Dog: SwXParagraph",
154 oText
.insertControlCharacter( oCursor
,
155 ControlCharacter
.PARAGRAPH_BREAK
, false );
156 oText
.insertString( oCursor
,
157 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG: SwXParagraph",
159 oText
.insertControlCharacter( oCursor
,
160 ControlCharacter
.PARAGRAPH_BREAK
, false );
161 oText
.insertControlCharacter( oCursor
,
162 ControlCharacter
.LINE_BREAK
, false );
164 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
){
165 log
.println("Exception occurred while inserting Text");
166 e
.printStackTrace(log
);
169 log
.println("creating a new environment for object");
170 tEnv
= new TestEnvironment(oObj
);
172 } // finish method getTestEnvironment
174 } // finish class SwXTextColumns