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
63 protected void initialize( TestParameters tParam
, PrintWriter log
) {
64 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
67 log
.println( "creating a textdocument" );
68 xTextDoc
= SOF
.createTextDoc( null );
69 } catch ( com
.sun
.star
.uno
.Exception e
) {
70 // Some exception occurs.FAILED
71 e
.printStackTrace( log
);
72 throw new StatusException( "Couldn't create document", e
);
77 * in general this method disposes the testenvironment and document
79 * @param tParam class which contains additional test parameters
80 * @param log class to log the test state and result
87 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
88 log
.println( " disposing xTextDoc " );
89 util
.DesktopTools
.closeDoc(xTextDoc
);
94 * creating a Testenvironment for the interfaces to be tested
96 * @param tParam class which contains additional test parameters
97 * @param log class to log the test state and result
99 * @return Status class
101 * @see TestParameters
104 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
106 XInterface oObj
= null;
108 // creation of testobject here
109 // first we write what we are intend to do to log file
110 log
.println( "creating a test environment" );
112 Object instance
= null;
114 // create testobject here
116 XMultiServiceFactory oDocMSF
= UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
118 Object FieldMaster
= oDocMSF
.createInstance
119 ( "com.sun.star.text.FieldMaster.Database" );
120 XPropertySet PFieldMaster
= UnoRuntime
.queryInterface
121 (XPropertySet
.class,FieldMaster
);
122 oObj
= (XInterface
) oDocMSF
.createInstance
123 ( "com.sun.star.text.TextField.Database" );
125 instance
= oDocMSF
.createInstance
126 ( "com.sun.star.text.TextField.DateTime" );
128 XDependentTextField xTF
= UnoRuntime
.queryInterface(XDependentTextField
.class,oObj
);
130 PFieldMaster
.setPropertyValue("DataBaseName","Address Book File");
131 PFieldMaster
.setPropertyValue("DataTableName","address");
132 PFieldMaster
.setPropertyValue("DataColumnName","FIRSTNAME");
133 XText the_Text
= xTextDoc
.getText();
134 XTextCursor the_Cursor
= the_Text
.createTextCursor();
135 XTextContent the_Field
= UnoRuntime
.queryInterface(XTextContent
.class,oObj
);
137 xTF
.attachTextFieldMaster(PFieldMaster
);
138 the_Text
.insertTextContent(the_Cursor
,the_Field
,false);
140 catch (Exception ex
) {
141 log
.println("Couldn't create instance");
142 ex
.printStackTrace(log
);
145 log
.println( "creating a new environment for FieldMaster object" );
146 TestEnvironment tEnv
= new TestEnvironment( oObj
);
149 tEnv
.addObjRelation("CONTENT", UnoRuntime
.queryInterface(XTextContent
.class,instance
));
150 tEnv
.addObjRelation("RANGE", xTextDoc
.getText().createTextCursor());
153 } // finish method getTestEnvironment
154 } // finish class SwXTextField