tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXTextView.java
blob9c72b2f0d27f38f6859ccdda2209ca1b62d2a156
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 com.sun.star.container.NoSuchElementException;
22 import com.sun.star.container.XNameContainer;
23 import com.sun.star.drawing.XDrawPage;
24 import com.sun.star.drawing.XShape;
25 import com.sun.star.lang.WrappedTargetException;
26 import java.io.PrintWriter;
27 import java.util.Comparator;
29 import lib.TestCase;
30 import lib.TestEnvironment;
31 import lib.TestParameters;
32 import util.SOfficeFactory;
34 import com.sun.star.container.XIndexAccess;
35 import com.sun.star.form.XForm;
36 import com.sun.star.frame.XController;
37 import com.sun.star.lang.XServiceInfo;
38 import com.sun.star.text.ControlCharacter;
39 import com.sun.star.text.XText;
40 import com.sun.star.text.XTextCursor;
41 import com.sun.star.text.XTextDocument;
42 import com.sun.star.text.XTextFrame;
43 import com.sun.star.uno.AnyConverter;
44 import com.sun.star.uno.Type;
45 import com.sun.star.uno.UnoRuntime;
46 import com.sun.star.util.XSearchDescriptor;
47 import com.sun.star.util.XSearchable;
48 import com.sun.star.view.XSelectionSupplier;
49 import util.FormTools;
50 import util.WriterTools;
52 /**
54 * initial description
55 * @see com.sun.star.text.XTextViewCursorSupplier
56 * @see com.sun.star.view.XControlAccess
57 * @see com.sun.star.view.XSelectionSupplier
58 * @see com.sun.star.view.XViewSettingsSupplier
61 public class SwXTextView extends TestCase {
63 XTextDocument xTextDoc;
65 boolean debug = false;
67 /**
68 * in general this method creates a testdocument
70 * @param tParam class which contains additional test parameters
71 * @param log class to log the test state and result
74 * @see TestParameters
75 * * @see PrintWriter
78 @Override
79 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
80 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
82 log.println( "creating a textdocument" );
83 xTextDoc = SOF.createTextDoc( null );
84 debug = tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE);
87 /**
88 * in general this method disposes the testenvironment and document
90 * @param tParam class which contains additional test parameters
91 * @param log class to log the test state and result
94 * @see TestParameters
95 * * @see PrintWriter
98 @Override
99 protected void cleanup( TestParameters tParam, PrintWriter log ) {
100 log.println( " disposing xTextDoc " );
101 util.DesktopTools.closeDoc(xTextDoc);
106 * * creating a TestEnvironment for the interfaces to be tested
108 * @param tParam class which contains additional test parameters
109 * @param log class to log the test state and result
111 * @return Status class
113 * @see TestParameters
114 * * @see PrintWriter
116 @Override
117 public TestEnvironment createTestEnvironment( TestParameters tParam,
118 PrintWriter log )
119 throws com.sun.star.uno.Exception
123 // creation of testobject here
124 log.println( "creating a test environment" );
126 XController xContr = xTextDoc.getCurrentController();
128 TestEnvironment tEnv = new TestEnvironment(xContr);
130 util.dbg.getSuppServices(xContr);
132 SOfficeFactory SOF=SOfficeFactory.getFactory( tParam.getMSF() );
133 XTextFrame first =null;
134 XTextFrame second =null;
136 Object oFrame1 = null;
137 Object oFrame2 = null;
138 XText oText = xTextDoc.getText();
139 XTextCursor oCursor = oText.createTextCursor();
140 oFrame1 = SOF.createInstance
141 (xTextDoc, "com.sun.star.text.TextFrame" );
142 first = UnoRuntime.queryInterface
143 ( XTextFrame.class, oFrame1);
144 oText.insertTextContent(oCursor,first, false);
145 first.getText().setString("Frame 1");
146 oFrame2 = SOF.createInstance(xTextDoc, "com.sun.star.text.TextFrame" );
147 second = UnoRuntime.queryInterface
148 ( XTextFrame.class, oFrame2);
149 oText.insertTextContent(oCursor,second, false);
150 second.getText().setString("Frame 2");
151 oText.insertString( oCursor,
152 "SwXTextRanges...SwXTextRanges...SwXTextRanges", false);
153 oText.insertControlCharacter( oCursor,
154 ControlCharacter.PARAGRAPH_BREAK, false);
155 oText.insertString( oCursor,
156 "bla...bla...", false);
158 XSearchable oSearch = UnoRuntime.queryInterface
159 (XSearchable.class, xTextDoc);
160 XSearchDescriptor xSDesc = oSearch.createSearchDescriptor();
161 xSDesc.setSearchString("SwXTextRanges");
162 XIndexAccess textRanges1 = oSearch.findAll(xSDesc);
164 xSDesc.setSearchString("bla");
165 XIndexAccess textRanges2 = oSearch.findAll(xSDesc);
167 tEnv.addObjRelation("Selections", new Object[] {
168 oFrame1, oFrame2, textRanges1, textRanges2});
169 tEnv.addObjRelation("Comparer", new Comparator<Object>() {
170 public int compare(Object o1, Object o2) {
171 XServiceInfo serv1 = UnoRuntime.queryInterface(XServiceInfo.class, o1);
172 XServiceInfo serv2 = UnoRuntime.queryInterface(XServiceInfo.class, o2);
174 String implName1 = serv1.getImplementationName();
175 String implName2 = serv2.getImplementationName();
176 if (!implName1.equals(implName2)) {
177 return -1;
180 XIndexAccess indAc1 = UnoRuntime.queryInterface(XIndexAccess.class, o1);
181 XIndexAccess indAc2 = UnoRuntime.queryInterface(XIndexAccess.class, o2);
183 if (indAc1 != null && indAc2 != null) {
184 int c1 = indAc1.getCount();
185 int c2 = indAc2.getCount();
186 return c1 == c2 ? 0 : 1;
189 XText text1 = UnoRuntime.queryInterface(XText.class, o1);
190 XText text2 = UnoRuntime.queryInterface(XText.class, o2);
192 if (text1 != null && text2 != null) {
193 return text1.getString().equals(text2.getString()) ? 0 : 1;
196 return -1;
200 XSelectionSupplier xsel = UnoRuntime.queryInterface(XSelectionSupplier.class,xContr);
201 xsel.select(second);
203 tEnv.addObjRelation("DOCUMENT",xTextDoc);
204 XForm myForm = null;
205 String kindOfControl="CommandButton";
206 XShape aShape = null;
207 log.println("adding control shape '" + kindOfControl + "'");
208 aShape = FormTools.createControlShape(xTextDoc, 3000,
209 4500, 15000, 10000,
210 kindOfControl);
213 log.println("adding relation for com.sun.star.view.XFormLayerAccess: XForm");
215 WriterTools.getDrawPage(xTextDoc).add(aShape);
217 try {
219 XDrawPage xDP = WriterTools.getDrawPage(xTextDoc);
220 if (xDP == null)
221 log.println("ERROR: could not get DrawPage");
223 XNameContainer xForms = FormTools.getForms(xDP);
224 if (xForms == null)
225 log.println("ERROR: could not get Forms");
227 log.println("the draw page contains following elements:");
228 String[] elements = FormTools.getForms(WriterTools.getDrawPage(xTextDoc)).getElementNames();
229 for (int i = 0; i< elements.length; i++){
230 log.println("Element[" + i + "] :" + elements[i]);
233 myForm = (XForm) AnyConverter.toObject(new Type(XForm.class), xForms.getByName("Standard"));
234 if (myForm == null){
235 log.println("ERROR: could not get 'Standard' from drawpage!");
236 if (debug){
237 log.println("the draw page contains following elements:");
240 else
241 tEnv.addObjRelation("XFormLayerAccess.XForm", myForm);
242 } catch (WrappedTargetException ex) {
243 log.println("ERROR: could not add ObjectRelation 'XFormLayerAccess.XForm': " + ex.toString());
244 } catch (com.sun.star.lang.IllegalArgumentException ex) {
245 log.println("ERROR: could not add ObjectRelation 'XFormLayerAccess.XForm': " + ex.toString());
246 } catch (NoSuchElementException ex) {
247 log.println("ERROR: could not add ObjectRelation 'XFormLayerAccess.XForm': " + ex.toString());
251 return tEnv;
253 } // finish method getTestEnvironment
254 } // finish class SwXTextView