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
.XMultiServiceFactory
;
39 import com
.sun
.star
.lang
.XServiceInfo
;
40 import com
.sun
.star
.text
.ControlCharacter
;
41 import com
.sun
.star
.text
.XText
;
42 import com
.sun
.star
.text
.XTextCursor
;
43 import com
.sun
.star
.text
.XTextDocument
;
44 import com
.sun
.star
.text
.XTextFrame
;
45 import com
.sun
.star
.uno
.AnyConverter
;
46 import com
.sun
.star
.uno
.Type
;
47 import com
.sun
.star
.uno
.UnoRuntime
;
48 import com
.sun
.star
.util
.XSearchDescriptor
;
49 import com
.sun
.star
.util
.XSearchable
;
50 import com
.sun
.star
.view
.XSelectionSupplier
;
51 import util
.FormTools
;
52 import util
.WriterTools
;
57 * @see com.sun.star.text.XTextViewCursorSupplier
58 * @see com.sun.star.view.XControlAccess
59 * @see com.sun.star.view.XSelectionSupplier
60 * @see com.sun.star.view.XViewSettingsSupplier
63 public class SwXTextView
extends TestCase
{
65 XTextDocument xTextDoc
;
67 boolean debug
= false;
70 * in general this method creates a testdocument
72 * @param tParam class which contains additional test parameters
73 * @param log class to log the test state and result
80 protected void initialize( TestParameters tParam
, PrintWriter log
) {
81 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)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
106 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
107 log
.println( " disposing xTextDoc " );
108 util
.DesktopTools
.closeDoc(xTextDoc
);
113 * * creating a Testenvironment for the interfaces to be tested
115 * @param tParam class which contains additional test parameters
116 * @param log class to log the test state and result
118 * @return Status class
120 * @see TestParameters
123 public TestEnvironment
createTestEnvironment( TestParameters tParam
,
124 PrintWriter log
)throws StatusException
{
127 // creation of testobject here
128 log
.println( "creating a test environment" );
130 XController xContr
= xTextDoc
.getCurrentController();
132 TestEnvironment tEnv
= new TestEnvironment(xContr
);
134 util
.dbg
.getSuppServices(xContr
);
136 SOfficeFactory SOF
=SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
137 XTextFrame first
=null;
138 XTextFrame second
=null;
140 Object oFrame1
= null;
141 Object oFrame2
= null;
143 XText oText
= xTextDoc
.getText();
144 XTextCursor oCursor
= oText
.createTextCursor();
145 oFrame1
= SOF
.createInstance
146 (xTextDoc
, "com.sun.star.text.TextFrame" );
147 first
= UnoRuntime
.queryInterface
148 ( XTextFrame
.class, oFrame1
);
149 oText
.insertTextContent(oCursor
,first
, false);
150 first
.getText().setString("Frame 1");
151 oFrame2
= SOF
.createInstance(xTextDoc
, "com.sun.star.text.TextFrame" );
152 second
= UnoRuntime
.queryInterface
153 ( XTextFrame
.class, oFrame2
);
154 oText
.insertTextContent(oCursor
,second
, false);
155 second
.getText().setString("Frame 2");
156 oText
.insertString( oCursor
,
157 "SwXTextRanges...SwXTextRanges...SwXTextRanges", false);
158 oText
.insertControlCharacter( oCursor
,
159 ControlCharacter
.PARAGRAPH_BREAK
, false);
160 oText
.insertString( oCursor
,
161 "bla...bla...", false);
162 } catch (Exception Ex
) {
163 Ex
.printStackTrace(log
);
164 throw new StatusException("Couldn't insert text table ", Ex
);
167 XSearchable oSearch
= UnoRuntime
.queryInterface
168 (XSearchable
.class, xTextDoc
);
169 XSearchDescriptor xSDesc
= oSearch
.createSearchDescriptor();
170 xSDesc
.setSearchString("SwXTextRanges");
171 XIndexAccess textRanges1
= oSearch
.findAll(xSDesc
);
173 xSDesc
.setSearchString("bla");
174 XIndexAccess textRanges2
= oSearch
.findAll(xSDesc
);
176 tEnv
.addObjRelation("Selections", new Object
[] {
177 oFrame1
, oFrame2
, textRanges1
, textRanges2
});
178 tEnv
.addObjRelation("Comparer", new Comparator
<Object
>() {
179 public int compare(Object o1
, Object o2
) {
180 XServiceInfo serv1
= UnoRuntime
.queryInterface(XServiceInfo
.class, o1
);
181 XServiceInfo serv2
= UnoRuntime
.queryInterface(XServiceInfo
.class, o2
);
183 String implName1
= serv1
.getImplementationName();
184 String implName2
= serv2
.getImplementationName();
185 if (!implName1
.equals(implName2
)) {
189 XIndexAccess indAc1
= UnoRuntime
.queryInterface(XIndexAccess
.class, o1
);
190 XIndexAccess indAc2
= UnoRuntime
.queryInterface(XIndexAccess
.class, o2
);
192 if (indAc1
!= null && indAc2
!= null) {
193 int c1
= indAc1
.getCount();
194 int c2
= indAc2
.getCount();
195 return c1
== c2 ?
0 : 1;
198 XText text1
= UnoRuntime
.queryInterface(XText
.class, o1
);
199 XText text2
= UnoRuntime
.queryInterface(XText
.class, o2
);
201 if (text1
!= null && text2
!= null) {
202 return text1
.getString().equals(text2
.getString()) ?
0 : 1;
209 XSelectionSupplier xsel
= UnoRuntime
.queryInterface(XSelectionSupplier
.class,xContr
);
212 } catch (Exception e
) {
213 log
.println("Couldn't select");
214 throw new StatusException( "Couldn't select", e
);
217 tEnv
.addObjRelation("DOCUMENT",xTextDoc
);
219 String kindOfControl
="CommandButton";
220 XShape aShape
= null;
222 log
.println("adding contol shape '" + kindOfControl
+ "'");
223 aShape
= FormTools
.createControlShape(xTextDoc
, 3000,
226 } catch (Exception e
){
227 e
.printStackTrace(log
);
228 throw new StatusException("Couldn't create following control shape : '" +
229 kindOfControl
+ "': ", e
);
234 log
.println("adding relation for com.sun.star.view.XFormLayerAccess: XForm");
236 WriterTools
.getDrawPage(xTextDoc
).add(aShape
);
240 XDrawPage xDP
= WriterTools
.getDrawPage(xTextDoc
);
242 log
.println("ERROR: could not get DrawPage");
244 XNameContainer xForms
= FormTools
.getForms(xDP
);
246 log
.println("ERROR: could not get Forms");
248 log
.println("the draw page contains folowing elemtens:");
249 String
[] elements
= FormTools
.getForms(WriterTools
.getDrawPage(xTextDoc
)).getElementNames();
250 for (int i
= 0; i
< elements
.length
; i
++){
251 log
.println("Element[" + i
+ "] :" + elements
[i
]);
254 myForm
= (XForm
) AnyConverter
.toObject(new Type(XForm
.class), xForms
.getByName("Standard"));
256 log
.println("ERROR: could not get 'Standard' from drawpage!");
258 log
.println("the draw page contains folowing elemtens:");
259 // String[] elements = FormTools.getForms(WriterTools.getDrawPage(xTextDoc)).getElementNames();
260 // for (int i = 0; i< elements.length; i++){
261 // log.println("Element[" + i + "] :" + elements[i]);
266 tEnv
.addObjRelation("XFormLayerAccess.XForm", myForm
);
267 } catch (WrappedTargetException ex
) {
268 log
.println("ERROR: could not add ObjectRelation 'XFormLayerAccess.XForm': " + ex
.toString());
269 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
270 log
.println("ERROR: could not add ObjectRelation 'XFormLayerAccess.XForm': " + ex
.toString());
271 } catch (NoSuchElementException ex
) {
272 log
.println("ERROR: could not add ObjectRelation 'XFormLayerAccess.XForm': " + ex
.toString());
278 } // finish method getTestEnvironment
279 } // finish class SwXTextView