1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwXTextColumns.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
41 import com
.sun
.star
.beans
.XPropertySet
;
42 import com
.sun
.star
.container
.XIndexAccess
;
43 import com
.sun
.star
.container
.XNameAccess
;
44 import com
.sun
.star
.lang
.XMultiServiceFactory
;
45 import com
.sun
.star
.style
.XStyle
;
46 import com
.sun
.star
.style
.XStyleFamiliesSupplier
;
47 import com
.sun
.star
.text
.ControlCharacter
;
48 import com
.sun
.star
.text
.XText
;
49 import com
.sun
.star
.text
.XTextColumns
;
50 import com
.sun
.star
.text
.XTextCursor
;
51 import com
.sun
.star
.text
.XTextDocument
;
52 import com
.sun
.star
.uno
.AnyConverter
;
53 import com
.sun
.star
.uno
.Type
;
54 import com
.sun
.star
.uno
.UnoRuntime
;
55 import com
.sun
.star
.uno
.XInterface
;
58 * Test for object which is represented by service
59 * <code>com.sun.star.text.TextColumns</code>. <p>
60 * Object implements the following interfaces :
62 * <li> <code>com::sun::star::text::XTextColumns</code></li>
63 * <li> <code>com::sun::star::text::TextColumns</code></li>
65 * This object test <b> is NOT </b> designed to be run in several
66 * threads concurently.
67 * @see com.sun.star.text.XTextColumns
68 * @see com.sun.star.text.TextColumns
69 * @see ifc.text._XTextColumns
70 * @see ifc.text._TextColumns
72 public class SwXTextColumns
extends TestCase
{
73 XTextDocument xTextDoc
;
76 * Creates text document.
78 protected void initialize( TestParameters tParam
, PrintWriter log
) {
79 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
81 log
.println( "creating a textdocument" );
82 xTextDoc
= SOF
.createTextDoc( null );
83 } catch ( com
.sun
.star
.uno
.Exception e
) {
84 e
.printStackTrace( log
);
85 throw new StatusException( "Couldn't create document", e
);
90 * Disposes text document.
92 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
93 log
.println( " disposing xTextDoc " );
94 util
.DesktopTools
.closeDoc(xTextDoc
);
98 * Creating a Testenvironment for the interfaces to be tested. After style
99 * families are gotten from text document using
100 * <code>XStyleFamiliesSupplier</code> interface, style family indexed '2'
101 * is obtained using <code>XIndexAccess</code> interface. Then style
102 * named 'Standard' is gotten from previously obtained style family using
103 * <code>XNameAccess</code> interface, and 'TextColumns' property value
104 * of this style is returned as a test component. Finally, several
105 * paragraphs within the text are inserted to a text document.
107 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
108 XInterface oObj
= null;
109 TestEnvironment tEnv
= null;
110 XStyle oStyle
= null;
112 log
.println( "creating a test environment" );
113 log
.println("getting PageStyle");
114 XStyleFamiliesSupplier oSFS
= (XStyleFamiliesSupplier
)
115 UnoRuntime
.queryInterface(XStyleFamiliesSupplier
.class, xTextDoc
);
116 XNameAccess oSF
= oSFS
.getStyleFamilies();
117 XIndexAccess oSFIA
= (XIndexAccess
)
118 UnoRuntime
.queryInterface(XIndexAccess
.class, oSF
);
121 XNameAccess oSFNA
= (XNameAccess
) AnyConverter
.toObject(
122 new Type(XNameAccess
.class),oSFIA
.getByIndex(2));
123 oStyle
= (XStyle
) AnyConverter
.toObject(
124 new Type(XStyle
.class),oSFNA
.getByName("Standard"));
125 } catch ( com
.sun
.star
.lang
.WrappedTargetException e
) {
126 log
.println("Error, exception occured while getting style.");
127 e
.printStackTrace(log
);
128 } catch ( com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
129 log
.println("Error, exception occured while getting style.");
130 e
.printStackTrace(log
);
131 } catch ( com
.sun
.star
.container
.NoSuchElementException e
) {
132 log
.println("Error, exception occured while getting style.");
133 e
.printStackTrace(log
);
134 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
135 log
.println("Error, exception occured while getting style.");
136 e
.printStackTrace(log
);
140 log
.println("Getting property ('TextColumns') value of style "
142 XPropertySet xProps
= (XPropertySet
)
143 UnoRuntime
.queryInterface(XPropertySet
.class,oStyle
);
144 oObj
= (XTextColumns
) AnyConverter
.toObject(
145 new Type(XTextColumns
.class),xProps
.getPropertyValue("TextColumns"));
146 } catch ( com
.sun
.star
.lang
.WrappedTargetException e
) {
147 log
.println("Exception occured while getting style property");
148 e
.printStackTrace(log
);
149 } catch ( com
.sun
.star
.beans
.UnknownPropertyException e
) {
150 log
.println("Exception occured while getting style property");
151 e
.printStackTrace(log
);
152 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
153 log
.println("Exception occured while getting style property");
154 e
.printStackTrace(log
);
157 XText oText
= xTextDoc
.getText();
158 XTextCursor oCursor
= oText
.createTextCursor();
160 log
.println( "inserting some text to text document..." );
162 for (int i
=0; i
< 5; i
++){
163 oText
.insertString( oCursor
,"Paragraph Number: " + i
, false);
164 oText
.insertString( oCursor
,
165 "The quick brown fox jumps over the lazy Dog: SwXParagraph",
167 oText
.insertControlCharacter( oCursor
,
168 ControlCharacter
.PARAGRAPH_BREAK
, false );
169 oText
.insertString( oCursor
,
170 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG: SwXParagraph",
172 oText
.insertControlCharacter( oCursor
,
173 ControlCharacter
.PARAGRAPH_BREAK
, false );
174 oText
.insertControlCharacter( oCursor
,
175 ControlCharacter
.LINE_BREAK
, false );
177 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
){
178 log
.println("Exception occured while inserting Text");
179 e
.printStackTrace(log
);
182 log
.println("creating a new environment for object");
183 tEnv
= new TestEnvironment(oObj
);
185 } // finish method getTestEnvironment
187 } // finish class SwXTextColumns