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
.XEnumerationAccess
;
31 import com
.sun
.star
.lang
.XMultiServiceFactory
;
32 import com
.sun
.star
.text
.XDependentTextField
;
33 import com
.sun
.star
.text
.XText
;
34 import com
.sun
.star
.text
.XTextContent
;
35 import com
.sun
.star
.text
.XTextCursor
;
36 import com
.sun
.star
.text
.XTextDocument
;
37 import com
.sun
.star
.text
.XTextFieldsSupplier
;
38 import com
.sun
.star
.uno
.UnoRuntime
;
39 import com
.sun
.star
.uno
.XInterface
;
43 * Object implements the following interfaces :
45 * <li> <code>com::sun::star::container::XEnumeration</code></li>
47 * This object test <b> is NOT </b> designed to be run in several
48 * threads concurently.
49 * @see com.sun.star.container.XEnumeration
50 * @see ifc.container._XEnumeration
52 public class SwXFieldEnumeration
extends TestCase
{
53 XTextDocument xTextDoc
;
56 * Creates text document.
58 protected void initialize( TestParameters tParam
, PrintWriter log
) {
59 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
61 log
.println( "creating a textdocument" );
62 xTextDoc
= SOF
.createTextDoc( null );
63 } catch ( com
.sun
.star
.uno
.Exception e
) {
64 e
.printStackTrace( log
);
65 throw new StatusException( "Couldn't create document", e
);
70 * Disposes text document.
72 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
73 log
.println( " disposing xTextDoc " );
74 util
.DesktopTools
.closeDoc(xTextDoc
);
78 * Creating a Testenvironment for the interfaces to be tested. FieldMaster
79 * object is created and attached to Bibliography database. After setting
80 * properties of created FieldMaster object, it is attached to the TextField
81 * object. Then TextField is inserted as TextContent to the text document.
82 * At the end, TextFields of text document are obtained and
83 * enumeration of these fields is created.<br>
84 * Creates instances of the services:
85 * <code>com.sun.star.text.FieldMaster.Database</code>,
86 * <code>com.sun.star.text.TextField.Database</code>.<br>
87 * Object relations created :
89 * <li> <code>'ENUM'</code> for
90 * {@link ifc.container._XEnumeration} : text fields</li>
93 public TestEnvironment
createTestEnvironment(
94 TestParameters tParam
, PrintWriter log
) throws StatusException
{
95 XInterface oObj
= null;
96 Object FieldMaster
= null;
97 XPropertySet PFieldMaster
= null;
98 XDependentTextField xTF
= null;
99 XEnumerationAccess xFEA
= null;
101 XTextCursor the_Cursor
;
102 XTextContent the_Field
;
104 log
.println( "creating a test environment" );
105 XMultiServiceFactory oDocMSF
= UnoRuntime
.queryInterface( XMultiServiceFactory
.class, xTextDoc
);
108 FieldMaster
= oDocMSF
.createInstance
109 ( "com.sun.star.text.FieldMaster.Database" );
110 PFieldMaster
= UnoRuntime
.queryInterface
111 (XPropertySet
.class,FieldMaster
);
113 oDocMSF
.createInstance("com.sun.star.text.TextField.Database");
114 xTF
= UnoRuntime
.queryInterface(XDependentTextField
.class,oObj
);
115 } catch ( com
.sun
.star
.uno
.Exception e
) {
116 e
.printStackTrace(log
);
120 PFieldMaster
.setPropertyValue("DataBaseName","Bibliography");
121 PFieldMaster
.setPropertyValue("DataTableName","biblio");
122 PFieldMaster
.setPropertyValue("DataColumnName","Address");
123 } catch ( com
.sun
.star
.lang
.WrappedTargetException e
) {
124 log
.println("Error: can't set PropertyValue to a FieldMaster");
125 e
.printStackTrace(log
);
126 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
127 log
.println("Error: can't set PropertyValue to a FieldMaster");
128 e
.printStackTrace(log
);
129 } catch ( com
.sun
.star
.beans
.UnknownPropertyException e
) {
130 log
.println("Error: can't set PropertyValue to a FieldMaster");
131 e
.printStackTrace(log
);
132 } catch ( com
.sun
.star
.beans
.PropertyVetoException e
) {
133 log
.println("Error: can't set PropertyValue to a FieldMaster");
134 e
.printStackTrace(log
);
137 the_Text
= xTextDoc
.getText();
138 the_Cursor
= the_Text
.createTextCursor();
139 the_Field
= UnoRuntime
.queryInterface(XTextContent
.class, oObj
);
142 xTF
.attachTextFieldMaster(PFieldMaster
);
143 the_Text
.insertTextContent(the_Cursor
,the_Field
,false);
144 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
145 e
.printStackTrace(log
);
146 throw new StatusException( "Couldn't create TextField", e
);
149 // create testobject here
150 XTextFieldsSupplier oTFS
= UnoRuntime
.queryInterface( XTextFieldsSupplier
.class, xTextDoc
);
151 xFEA
= oTFS
.getTextFields();
152 oObj
= oTFS
.getTextFields().createEnumeration();
154 log
.println( "creating a new environment for FieldEnumeration object" );
155 TestEnvironment tEnv
= new TestEnvironment( oObj
);
157 tEnv
.addObjRelation("ENUM", xFEA
);
160 } // finish method getTestEnvironment
162 } // finish class SwXFieldEnumeration