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 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
.StatusException
;
31 import lib
.TestEnvironment
;
32 import lib
.TestParameters
;
33 import util
.SOfficeFactory
;
35 import com
.sun
.star
.container
.XIndexAccess
;
36 import com
.sun
.star
.form
.XForm
;
37 import com
.sun
.star
.frame
.XController
;
38 import com
.sun
.star
.lang
.XServiceInfo
;
39 import com
.sun
.star
.text
.ControlCharacter
;
40 import com
.sun
.star
.text
.XText
;
41 import com
.sun
.star
.text
.XTextCursor
;
42 import com
.sun
.star
.text
.XTextDocument
;
43 import com
.sun
.star
.text
.XTextFrame
;
44 import com
.sun
.star
.uno
.AnyConverter
;
45 import com
.sun
.star
.uno
.Type
;
46 import com
.sun
.star
.uno
.UnoRuntime
;
47 import com
.sun
.star
.util
.XSearchDescriptor
;
48 import com
.sun
.star
.util
.XSearchable
;
49 import com
.sun
.star
.view
.XSelectionSupplier
;
50 import util
.FormTools
;
51 import util
.WriterTools
;
56 * @see com.sun.star.text.XTextViewCursorSupplier
57 * @see com.sun.star.view.XControlAccess
58 * @see com.sun.star.view.XSelectionSupplier
59 * @see com.sun.star.view.XViewSettingsSupplier
62 public class SwXTextView
extends TestCase
{
64 XTextDocument xTextDoc
;
66 boolean debug
= false;
69 * in general this method creates a testdocument
71 * @param tParam class which contains additional test parameters
72 * @param log class to log the test state and result
80 protected void initialize( TestParameters tParam
, PrintWriter log
) {
81 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
84 log
.println( "creating a textdocument" );
85 xTextDoc
= SOF
.createTextDoc( null );
86 debug
= tParam
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
);
88 } catch ( com
.sun
.star
.uno
.Exception e
) {
89 // Some exception occurs.FAILED
90 e
.printStackTrace( log
);
91 throw new StatusException( "Couldn't create document", e
);
96 * in general this method disposes the testenvironment and document
98 * @param tParam class which contains additional test parameters
99 * @param log class to log the test state and result
102 * @see TestParameters
107 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
108 log
.println( " disposing xTextDoc " );
109 util
.DesktopTools
.closeDoc(xTextDoc
);
114 * * creating a Testenvironment for the interfaces to be tested
116 * @param tParam class which contains additional test parameters
117 * @param log class to log the test state and result
119 * @return Status class
121 * @see TestParameters
125 public TestEnvironment
createTestEnvironment( TestParameters tParam
,
126 PrintWriter log
)throws StatusException
{
129 // creation of testobject here
130 log
.println( "creating a test environment" );
132 XController xContr
= xTextDoc
.getCurrentController();
134 TestEnvironment tEnv
= new TestEnvironment(xContr
);
136 util
.dbg
.getSuppServices(xContr
);
138 SOfficeFactory SOF
=SOfficeFactory
.getFactory( tParam
.getMSF() );
139 XTextFrame first
=null;
140 XTextFrame second
=null;
142 Object oFrame1
= null;
143 Object oFrame2
= null;
145 XText oText
= xTextDoc
.getText();
146 XTextCursor oCursor
= oText
.createTextCursor();
147 oFrame1
= SOF
.createInstance
148 (xTextDoc
, "com.sun.star.text.TextFrame" );
149 first
= UnoRuntime
.queryInterface
150 ( XTextFrame
.class, oFrame1
);
151 oText
.insertTextContent(oCursor
,first
, false);
152 first
.getText().setString("Frame 1");
153 oFrame2
= SOF
.createInstance(xTextDoc
, "com.sun.star.text.TextFrame" );
154 second
= UnoRuntime
.queryInterface
155 ( XTextFrame
.class, oFrame2
);
156 oText
.insertTextContent(oCursor
,second
, false);
157 second
.getText().setString("Frame 2");
158 oText
.insertString( oCursor
,
159 "SwXTextRanges...SwXTextRanges...SwXTextRanges", false);
160 oText
.insertControlCharacter( oCursor
,
161 ControlCharacter
.PARAGRAPH_BREAK
, false);
162 oText
.insertString( oCursor
,
163 "bla...bla...", false);
164 } catch (Exception Ex
) {
165 Ex
.printStackTrace(log
);
166 throw new StatusException("Couldn't insert text table ", Ex
);
169 XSearchable oSearch
= UnoRuntime
.queryInterface
170 (XSearchable
.class, xTextDoc
);
171 XSearchDescriptor xSDesc
= oSearch
.createSearchDescriptor();
172 xSDesc
.setSearchString("SwXTextRanges");
173 XIndexAccess textRanges1
= oSearch
.findAll(xSDesc
);
175 xSDesc
.setSearchString("bla");
176 XIndexAccess textRanges2
= oSearch
.findAll(xSDesc
);
178 tEnv
.addObjRelation("Selections", new Object
[] {
179 oFrame1
, oFrame2
, textRanges1
, textRanges2
});
180 tEnv
.addObjRelation("Comparer", new Comparator
<Object
>() {
181 public int compare(Object o1
, Object o2
) {
182 XServiceInfo serv1
= UnoRuntime
.queryInterface(XServiceInfo
.class, o1
);
183 XServiceInfo serv2
= UnoRuntime
.queryInterface(XServiceInfo
.class, o2
);
185 String implName1
= serv1
.getImplementationName();
186 String implName2
= serv2
.getImplementationName();
187 if (!implName1
.equals(implName2
)) {
191 XIndexAccess indAc1
= UnoRuntime
.queryInterface(XIndexAccess
.class, o1
);
192 XIndexAccess indAc2
= UnoRuntime
.queryInterface(XIndexAccess
.class, o2
);
194 if (indAc1
!= null && indAc2
!= null) {
195 int c1
= indAc1
.getCount();
196 int c2
= indAc2
.getCount();
197 return c1
== c2 ?
0 : 1;
200 XText text1
= UnoRuntime
.queryInterface(XText
.class, o1
);
201 XText text2
= UnoRuntime
.queryInterface(XText
.class, o2
);
203 if (text1
!= null && text2
!= null) {
204 return text1
.getString().equals(text2
.getString()) ?
0 : 1;
211 XSelectionSupplier xsel
= UnoRuntime
.queryInterface(XSelectionSupplier
.class,xContr
);
214 } catch (Exception e
) {
215 log
.println("Couldn't select");
216 throw new StatusException( "Couldn't select", e
);
219 tEnv
.addObjRelation("DOCUMENT",xTextDoc
);
221 String kindOfControl
="CommandButton";
222 XShape aShape
= null;
224 log
.println("adding contol shape '" + kindOfControl
+ "'");
225 aShape
= FormTools
.createControlShape(xTextDoc
, 3000,
228 } catch (Exception e
){
229 e
.printStackTrace(log
);
230 throw new StatusException("Couldn't create following control shape : '" +
231 kindOfControl
+ "': ", e
);
236 log
.println("adding relation for com.sun.star.view.XFormLayerAccess: XForm");
238 WriterTools
.getDrawPage(xTextDoc
).add(aShape
);
242 XDrawPage xDP
= WriterTools
.getDrawPage(xTextDoc
);
244 log
.println("ERROR: could not get DrawPage");
246 XNameContainer xForms
= FormTools
.getForms(xDP
);
248 log
.println("ERROR: could not get Forms");
250 log
.println("the draw page contains following elements:");
251 String
[] elements
= FormTools
.getForms(WriterTools
.getDrawPage(xTextDoc
)).getElementNames();
252 for (int i
= 0; i
< elements
.length
; i
++){
253 log
.println("Element[" + i
+ "] :" + elements
[i
]);
256 myForm
= (XForm
) AnyConverter
.toObject(new Type(XForm
.class), xForms
.getByName("Standard"));
258 log
.println("ERROR: could not get 'Standard' from drawpage!");
260 log
.println("the draw page contains following elements:");
264 tEnv
.addObjRelation("XFormLayerAccess.XForm", myForm
);
265 } catch (WrappedTargetException ex
) {
266 log
.println("ERROR: could not add ObjectRelation 'XFormLayerAccess.XForm': " + ex
.toString());
267 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
268 log
.println("ERROR: could not add ObjectRelation 'XFormLayerAccess.XForm': " + ex
.toString());
269 } catch (NoSuchElementException ex
) {
270 log
.println("ERROR: could not add ObjectRelation 'XFormLayerAccess.XForm': " + ex
.toString());
276 } // finish method getTestEnvironment
277 } // finish class SwXTextView