Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXFieldEnumeration.java
blobdcfbf1c2f81e320e85ff4c3ea624e21da0eee2d6
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.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;
42 /**
43 * Object implements the following interfaces :
44 * <ul>
45 * <li> <code>com::sun::star::container::XEnumeration</code></li>
46 * </ul> <p>
47 * This object test <b> is NOT </b> designed to be run in several
48 * threads concurrently.
49 * @see com.sun.star.container.XEnumeration
50 * @see ifc.container._XEnumeration
52 public class SwXFieldEnumeration extends TestCase {
53 XTextDocument xTextDoc;
55 /**
56 * Creates text document.
58 @Override
59 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
60 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
61 log.println( "creating a textdocument" );
62 xTextDoc = SOF.createTextDoc( null );
65 /**
66 * Disposes text document.
68 @Override
69 protected void cleanup( TestParameters tParam, PrintWriter log ) {
70 log.println( " disposing xTextDoc " );
71 util.DesktopTools.closeDoc(xTextDoc);
74 /**
75 * Creating a TestEnvironment for the interfaces to be tested. FieldMaster
76 * object is created and attached to Bibliography database. After setting
77 * properties of created FieldMaster object, it is attached to the TextField
78 * object. Then TextField is inserted as TextContent to the text document.
79 * At the end, TextFields of text document are obtained and
80 * enumeration of these fields is created.<br>
81 * Creates instances of the services:
82 * <code>com.sun.star.text.FieldMaster.Database</code>,
83 * <code>com.sun.star.text.TextField.Database</code>.<br>
84 * Object relations created :
85 * <ul>
86 * <li> <code>'ENUM'</code> for
87 * {@link ifc.container._XEnumeration} : text fields</li>
88 * </ul>
90 @Override
91 public TestEnvironment createTestEnvironment(
92 TestParameters tParam, PrintWriter log ) throws StatusException {
93 XInterface oObj = null;
94 Object FieldMaster = null;
95 XPropertySet PFieldMaster = null;
96 XDependentTextField xTF = null;
97 XEnumerationAccess xFEA = null;
98 XText the_Text;
99 XTextCursor the_Cursor;
100 XTextContent the_Field;
102 log.println( "creating a test environment" );
103 XMultiServiceFactory oDocMSF = UnoRuntime.queryInterface( XMultiServiceFactory.class, xTextDoc );
105 try {
106 FieldMaster = oDocMSF.createInstance
107 ( "com.sun.star.text.FieldMaster.Database" );
108 PFieldMaster = UnoRuntime.queryInterface
109 (XPropertySet.class,FieldMaster);
110 oObj = (XInterface)
111 oDocMSF.createInstance("com.sun.star.text.TextField.Database");
112 xTF = UnoRuntime.queryInterface(XDependentTextField.class,oObj);
113 } catch ( com.sun.star.uno.Exception e ) {
114 e.printStackTrace(log);
117 try {
118 PFieldMaster.setPropertyValue("DataBaseName","Bibliography");
119 PFieldMaster.setPropertyValue("DataTableName","biblio");
120 PFieldMaster.setPropertyValue("DataColumnName","Address");
121 } catch ( com.sun.star.lang.WrappedTargetException e ) {
122 log.println("Error: can't set PropertyValue to a FieldMaster");
123 e.printStackTrace(log);
124 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
125 log.println("Error: can't set PropertyValue to a FieldMaster");
126 e.printStackTrace(log);
127 } catch ( com.sun.star.beans.UnknownPropertyException e ) {
128 log.println("Error: can't set PropertyValue to a FieldMaster");
129 e.printStackTrace(log);
130 } catch ( com.sun.star.beans.PropertyVetoException e ) {
131 log.println("Error: can't set PropertyValue to a FieldMaster");
132 e.printStackTrace(log);
135 the_Text = xTextDoc.getText();
136 the_Cursor = the_Text.createTextCursor();
137 the_Field = UnoRuntime.queryInterface(XTextContent.class, oObj);
139 xTF.attachTextFieldMaster(PFieldMaster);
140 the_Text.insertTextContent(the_Cursor,the_Field,false);
142 // create testobject here
143 XTextFieldsSupplier oTFS = UnoRuntime.queryInterface( XTextFieldsSupplier.class, xTextDoc );
144 xFEA = oTFS.getTextFields();
145 oObj = oTFS.getTextFields().createEnumeration();
147 log.println( "creating a new environment for FieldEnumeration object" );
148 TestEnvironment tEnv = new TestEnvironment( oObj );
150 tEnv.addObjRelation("ENUM", xFEA);
152 return tEnv;
153 } // finish method getTestEnvironment
155 } // finish class SwXFieldEnumeration