tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXTextField.java
blob61afb8e30e5a391c5f6a61b7405e4af0f7f90ae9
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.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.SOfficeFactory;
28 import com.sun.star.beans.XPropertySet;
29 import com.sun.star.lang.XMultiServiceFactory;
30 import com.sun.star.text.XDependentTextField;
31 import com.sun.star.text.XText;
32 import com.sun.star.text.XTextContent;
33 import com.sun.star.text.XTextCursor;
34 import com.sun.star.text.XTextDocument;
35 import com.sun.star.uno.UnoRuntime;
36 import com.sun.star.uno.XInterface;
38 /**
40 * initial description
41 * @see com.sun.star.lang.XComponent
42 * @see com.sun.star.text.TextContent
43 * @see com.sun.star.text.XTextContent
44 * @see com.sun.star.text.XTextField
47 public class SwXTextField extends TestCase {
49 XTextDocument xTextDoc;
51 /**
52 * in general this method creates a testdocument
54 * @param tParam class which contains additional test parameters
55 * @param log class to log the test state and result
58 * @see TestParameters
59 * @see PrintWriter
62 @Override
63 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
64 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
65 log.println( "creating a textdocument" );
66 xTextDoc = SOF.createTextDoc( null );
69 /**
70 * in general this method disposes the testenvironment and document
72 * @param tParam class which contains additional test parameters
73 * @param log class to log the test state and result
76 * @see TestParameters
77 * @see PrintWriter
80 @Override
81 protected void cleanup( TestParameters tParam, PrintWriter log ) {
82 log.println( " disposing xTextDoc " );
83 util.DesktopTools.closeDoc(xTextDoc);
87 /**
88 * creating a TestEnvironment for the interfaces to be tested
90 * @param tParam class which contains additional test parameters
91 * @param log class to log the test state and result
93 * @return Status class
95 * @see TestParameters
96 * @see PrintWriter
98 @Override
99 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
101 XInterface oObj = null;
103 // creation of testobject here
104 // first we write what we are intend to do to log file
105 log.println( "creating a test environment" );
107 Object instance = null;
109 // create testobject here
110 try {
111 XMultiServiceFactory oDocMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
113 Object FieldMaster = oDocMSF.createInstance
114 ( "com.sun.star.text.FieldMaster.Database" );
115 XPropertySet PFieldMaster = UnoRuntime.queryInterface
116 (XPropertySet.class,FieldMaster);
117 oObj = (XInterface) oDocMSF.createInstance
118 ( "com.sun.star.text.TextField.Database" );
120 instance = oDocMSF.createInstance
121 ( "com.sun.star.text.TextField.DateTime" );
123 XDependentTextField xTF = UnoRuntime.queryInterface(XDependentTextField.class,oObj);
125 PFieldMaster.setPropertyValue("DataBaseName","Address Book File");
126 PFieldMaster.setPropertyValue("DataTableName","address");
127 PFieldMaster.setPropertyValue("DataColumnName","FIRSTNAME");
128 XText the_Text = xTextDoc.getText();
129 XTextCursor the_Cursor = the_Text.createTextCursor();
130 XTextContent the_Field = UnoRuntime.queryInterface(XTextContent.class,oObj);
132 xTF.attachTextFieldMaster(PFieldMaster);
133 the_Text.insertTextContent(the_Cursor,the_Field,false);
135 catch (Exception ex) {
136 log.println("Couldn't create instance");
137 ex.printStackTrace(log);
140 log.println( "creating a new environment for FieldMaster object" );
141 TestEnvironment tEnv = new TestEnvironment( oObj );
144 tEnv.addObjRelation("CONTENT", UnoRuntime.queryInterface(XTextContent.class,instance));
145 tEnv.addObjRelation("RANGE", xTextDoc.getText().createTextCursor());
147 return tEnv;
148 } // finish method getTestEnvironment
149 } // finish class SwXTextField