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
.lang
.XMultiServiceFactory
;
31 import com
.sun
.star
.text
.XDependentTextField
;
32 import com
.sun
.star
.text
.XText
;
33 import com
.sun
.star
.text
.XTextContent
;
34 import com
.sun
.star
.text
.XTextCursor
;
35 import com
.sun
.star
.text
.XTextDocument
;
36 import com
.sun
.star
.uno
.UnoRuntime
;
37 import com
.sun
.star
.uno
.XInterface
;
42 * @see com.sun.star.lang.XComponent
43 * @see com.sun.star.text.TextContent
44 * @see com.sun.star.text.XTextContent
45 * @see com.sun.star.text.XTextField
48 public class SwXTextField
extends TestCase
{
50 XTextDocument xTextDoc
;
53 * in general this method creates a testdocument
55 * @param tParam class which contains additional test parameters
56 * @param log class to log the test state and result
64 protected void initialize( TestParameters tParam
, PrintWriter log
) {
65 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
68 log
.println( "creating a textdocument" );
69 xTextDoc
= SOF
.createTextDoc( null );
70 } catch ( com
.sun
.star
.uno
.Exception e
) {
71 // Some exception occurs.FAILED
72 e
.printStackTrace( log
);
73 throw new StatusException( "Couldn't create document", e
);
78 * in general this method disposes the testenvironment and document
80 * @param tParam class which contains additional test parameters
81 * @param log class to log the test state and result
89 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
90 log
.println( " disposing xTextDoc " );
91 util
.DesktopTools
.closeDoc(xTextDoc
);
96 * creating a Testenvironment for the interfaces to be tested
98 * @param tParam class which contains additional test parameters
99 * @param log class to log the test state and result
101 * @return Status class
103 * @see TestParameters
107 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
109 XInterface oObj
= null;
111 // creation of testobject here
112 // first we write what we are intend to do to log file
113 log
.println( "creating a test environment" );
115 Object instance
= null;
117 // create testobject here
119 XMultiServiceFactory oDocMSF
= UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
121 Object FieldMaster
= oDocMSF
.createInstance
122 ( "com.sun.star.text.FieldMaster.Database" );
123 XPropertySet PFieldMaster
= UnoRuntime
.queryInterface
124 (XPropertySet
.class,FieldMaster
);
125 oObj
= (XInterface
) oDocMSF
.createInstance
126 ( "com.sun.star.text.TextField.Database" );
128 instance
= oDocMSF
.createInstance
129 ( "com.sun.star.text.TextField.DateTime" );
131 XDependentTextField xTF
= UnoRuntime
.queryInterface(XDependentTextField
.class,oObj
);
133 PFieldMaster
.setPropertyValue("DataBaseName","Address Book File");
134 PFieldMaster
.setPropertyValue("DataTableName","address");
135 PFieldMaster
.setPropertyValue("DataColumnName","FIRSTNAME");
136 XText the_Text
= xTextDoc
.getText();
137 XTextCursor the_Cursor
= the_Text
.createTextCursor();
138 XTextContent the_Field
= UnoRuntime
.queryInterface(XTextContent
.class,oObj
);
140 xTF
.attachTextFieldMaster(PFieldMaster
);
141 the_Text
.insertTextContent(the_Cursor
,the_Field
,false);
143 catch (Exception ex
) {
144 log
.println("Couldn't create instance");
145 ex
.printStackTrace(log
);
148 log
.println( "creating a new environment for FieldMaster object" );
149 TestEnvironment tEnv
= new TestEnvironment( oObj
);
152 tEnv
.addObjRelation("CONTENT", UnoRuntime
.queryInterface(XTextContent
.class,instance
));
153 tEnv
.addObjRelation("RANGE", xTextDoc
.getText().createTextCursor());
156 } // finish method getTestEnvironment
157 } // finish class SwXTextField