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 complex
.calcPreview
;
21 // import complexlib.ComplexTestCase;
23 import com
.sun
.star
.awt
.XWindow
;
24 import com
.sun
.star
.container
.XIndexAccess
;
25 import com
.sun
.star
.frame
.XController
;
26 import com
.sun
.star
.frame
.XDispatch
;
27 import com
.sun
.star
.frame
.XDispatchProvider
;
28 import com
.sun
.star
.frame
.XModel
;
29 // import com.sun.star.lang.XComponent;
30 import com
.sun
.star
.lang
.XMultiServiceFactory
;
31 import com
.sun
.star
.sheet
.XSpreadsheet
;
32 // import com.sun.star.sheet.XSpreadsheetDocument;
33 import com
.sun
.star
.sheet
.XSpreadsheets
;
34 import com
.sun
.star
.table
.XCell
;
35 // import com.sun.star.uno.Any;
36 import com
.sun
.star
.uno
.AnyConverter
;
37 import com
.sun
.star
.uno
.UnoRuntime
;
38 import com
.sun
.star
.uno
.XInterface
;
39 import com
.sun
.star
.util
.URL
;
40 import com
.sun
.star
.util
.XURLTransformer
;
41 import com
.sun
.star
.accessibility
.AccessibleRole
;
42 import com
.sun
.star
.accessibility
.XAccessible
;
43 import com
.sun
.star
.accessibility
.XAccessibleText
;
44 import com
.sun
.star
.accessibility
.XAccessibleValue
;
45 import com
.sun
.star
.accessibility
.XAccessibleComponent
;
46 import com
.sun
.star
.accessibility
.XAccessibleContext
;
48 import util
.AccessibilityTools
;
49 import util
.SOfficeFactory
;
52 import com
.sun
.star
.beans
.XPropertySet
;
53 // import com.sun.star.beans.XPropertySetInfo;
54 import com
.sun
.star
.container
.XNameAccess
;
55 import com
.sun
.star
.lang
.XComponent
;
56 import com
.sun
.star
.sheet
.XHeaderFooterContent
;
57 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
58 import com
.sun
.star
.style
.XStyle
;
59 import com
.sun
.star
.style
.XStyleFamiliesSupplier
;
60 import com
.sun
.star
.text
.XText
;
61 // import com.sun.star.drawing.XDrawPageSupplier;
62 // import com.sun.star.drawing.XDrawPage;
63 // import com.sun.star.drawing.XShape;
64 // import com.sun.star.drawing.XShapes;
67 // import com.sun.star.beans.Property;
68 // import com.sun.star.lang.XServiceInfo;
72 // import org.junit.After;
73 import org
.junit
.AfterClass
;
74 import org
.junit
.Before
;
75 import org
.junit
.BeforeClass
;
76 import org
.junit
.Test
;
77 import org
.openoffice
.test
.OfficeConnection
;
78 import static org
.junit
.Assert
.*;
81 * A complex test for the preview of Calc documents. This complex test
82 * needs interaction from the user: documents have to be resized and moved.
84 public class ViewForwarder
{
86 /** The MultiServiceFactory **/
87 private XMultiServiceFactory mXMSF
= null;
89 /** Get all test methods.
90 * @return The test methods.
92 // public String[] getTestMethodNames() {
93 // return new String[]{"checkPositiveViewForwarder",
94 // "checkNegativeViewForwarder",
95 // "checkPreviewHeaderCells",
96 // "checkPreviewShape"
101 * Get a MultiServiceFactory from the Office before the test.
103 @Before public void before()
105 mXMSF
= UnoRuntime
.queryInterface(XMultiServiceFactory
.class, connection
.getComponentContext().getServiceManager());
106 // SOfficeFactory SOF = SOfficeFactory.getFactory(mXMSF);
108 // param = new TestParameters();
109 // param.put("ServiceFactory", xMsf);
110 // mXMSF = (XMultiServiceFactory)param.getMSF();
114 /** Create a spreadsheet document, insert some text, header and footer.
115 * Let the user resize the document and check the contents.
117 @Test public void checkPositiveViewForwarder() {
118 SOfficeFactory SOF
= SOfficeFactory
.getFactory( mXMSF
);
119 XSpreadsheetDocument xSpreadsheetDoc
= null;
122 System
.out
.println("Creating a spreadsheet document");
123 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
124 } catch (com
.sun
.star
.uno
.Exception e
) {
125 fail(e
.getMessage());
129 XInterface oObj
= null;
131 // inserting some content to have non-empty page preview
134 XSpreadsheets oSheets
= xSpreadsheetDoc
.getSheets() ;
135 XIndexAccess oIndexSheets
=
136 UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
137 Object o
= oIndexSheets
.getByIndex(0);
138 XSpreadsheet oSheet
= (XSpreadsheet
)AnyConverter
.toObject(
139 new com
.sun
.star
.uno
.Type(XSpreadsheet
.class), o
);
140 xCell
= oSheet
.getCellByPosition(0, 0) ;
141 xCell
.setFormula("ScAccessiblePageHeader");
143 xCell
= oSheet
.getCellByPosition(0, 1) ;
144 xCell
.setFormula("Cell 1");
145 xCell
= oSheet
.getCellByPosition(0, 2) ;
146 xCell
.setFormula("Cell 2");
147 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
148 System
.out
.println("Exception ceating relation :");
149 fail(e
.getMessage());
150 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
151 System
.out
.println("Exception ceating relation :");
152 fail(e
.getMessage());
153 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
154 System
.out
.println("Exception ceating relation :");
155 fail(e
.getMessage());
159 UnoRuntime
.queryInterface(XModel
.class, xSpreadsheetDoc
);
161 XController xController
= aModel
.getCurrentController();
164 XStyleFamiliesSupplier StyleFam
=
165 UnoRuntime
.queryInterface(
166 XStyleFamiliesSupplier
.class,
168 XNameAccess StyleFamNames
= StyleFam
.getStyleFamilies();
169 XStyle StdStyle
= null;
172 Object o
= StyleFamNames
.getByName("PageStyles");
173 XNameAccess PageStyles
= (XNameAccess
)AnyConverter
.toObject(
174 new com
.sun
.star
.uno
.Type(XNameAccess
.class), o
);
176 o
= PageStyles
.getByName("Default");
177 StdStyle
= (XStyle
)AnyConverter
.toObject(
178 new com
.sun
.star
.uno
.Type(XStyle
.class), o
);
179 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
180 fail(e
.getMessage());
181 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
182 fail(e
.getMessage());
184 } catch(com
.sun
.star
.container
.NoSuchElementException e
){
185 fail(e
.getMessage());
189 //get the property-set
190 final XPropertySet PropSet
=
191 UnoRuntime
.queryInterface(XPropertySet
.class, StdStyle
);
193 XHeaderFooterContent RPHFC
= null;
197 Object o
= PropSet
.getPropertyValue("RightPageHeaderContent");
198 RPHFC
= (XHeaderFooterContent
)AnyConverter
.toObject(
199 new com
.sun
.star
.uno
.Type(XHeaderFooterContent
.class), o
);
201 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
202 fail(e
.getMessage());
203 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
204 fail(e
.getMessage());
206 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
){
207 fail(e
.getMessage());
211 // insert text into header
212 XText center
= RPHFC
.getCenterText();
213 center
.setString("First line \n\r Second line \n\r third line ");
215 PropSet
.setPropertyValue("RightPageHeaderContent",RPHFC
);
216 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
217 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
218 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
219 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {}
224 Object o
= PropSet
.getPropertyValue("RightPageHeaderContent");
225 RPHFC
= (XHeaderFooterContent
)AnyConverter
.toObject(
226 new com
.sun
.star
.uno
.Type(XHeaderFooterContent
.class), o
);
227 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
228 fail(e
.getMessage());
229 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
230 fail(e
.getMessage());
232 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
){
233 fail(e
.getMessage());
237 // insert text into footer
238 center
= RPHFC
.getCenterText();
239 center
.setString("Third last line\n\r Second last line\n\r last line");
241 PropSet
.setPropertyValue("RightPageFooterContent",RPHFC
);
242 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
243 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
244 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
245 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {}
247 // switching to 'Page Preview' mode
249 XDispatchProvider xDispProv
=
250 UnoRuntime
.queryInterface(XDispatchProvider
.class, xController
);
251 XURLTransformer xParser
=
252 UnoRuntime
.queryInterface(XURLTransformer
.class,
253 mXMSF
.createInstance("com.sun.star.util.URLTransformer"));
254 // Because it's an in/out parameter we must use an
255 // array of URL objects.
256 URL
[] aParseURL
= new URL
[1];
257 aParseURL
[0] = new URL();
258 aParseURL
[0].Complete
= ".uno:PrintPreview";
259 xParser
.parseStrict(aParseURL
);
260 URL aURL
= aParseURL
[0];
261 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
262 if(xDispatcher
!= null)
264 xDispatcher
.dispatch( aURL
, null );
266 } catch (com
.sun
.star
.uno
.Exception e
) {
267 fail("Couldn't change mode");
273 } catch (InterruptedException ex
) {}
275 System
.out
.println("Press any key after resizing ");
277 byte[]b
= new byte[16];
279 } catch (Exception e
) {
283 // get the accessible content
284 AccessibilityTools at
= new AccessibilityTools();
286 XWindow xWindow
= AccessibilityTools
.getCurrentWindow(mXMSF
, aModel
);
287 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
288 XAccessible parent
= null;
291 parent
= AccessibilityTools
.getAccessibleObjectForRole
292 (xRoot
, AccessibleRole
.HEADER
, "").getAccessibleChild(0);
293 oObj
= parent
.getAccessibleContext().getAccessibleChild(0);
294 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
295 fail(iabe
.getMessage());
299 System
.out
.println("ImplementationName " + utils
.getImplName(oObj
));
301 XAccessibleComponent accPC
=
302 UnoRuntime
.queryInterface(XAccessibleComponent
.class, parent
);
304 System
.out
.println("Parent-BoundsX= "+accPC
.getBounds().X
);
305 System
.out
.println("Parent-BoundsY= "+accPC
.getBounds().Y
);
306 System
.out
.println("Parent-BoundsWidth= "+accPC
.getBounds().Width
);
307 System
.out
.println("Parent-BoundsHeight= "+accPC
.getBounds().Height
);
309 XAccessibleComponent accPPC
=
310 UnoRuntime
.queryInterface(XAccessibleComponent
.class,
311 parent
.getAccessibleContext().getAccessibleParent());
313 System
.out
.println("P-Parent-BoundsX= "+accPPC
.getBounds().X
);
314 System
.out
.println("P-Parent-BoundsY= "+accPPC
.getBounds().Y
);
315 System
.out
.println("P-Parent-BoundsWidth= "+accPPC
.getBounds().Width
);
316 System
.out
.println("P-Parent-BoundsHeight= "+accPPC
.getBounds().Height
);
320 } catch (InterruptedException ex
) {}
322 System
.out
.println("Press any key when the second line is on top");
324 byte[]b
= new byte[16];
326 } catch (Exception e
) {
331 System
.out
.println("ChildCount: "+
332 parent
.getAccessibleContext().getAccessibleChildCount());
333 System
.out
.println("Getting child 0 again");
334 oObj
= parent
.getAccessibleContext().getAccessibleChild(0);
335 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
336 fail(iabe
.getMessage());
340 XAccessibleText accT
=
341 UnoRuntime
.queryInterface(XAccessibleText
.class, oObj
);
342 System
.out
.println("Getting the text: "+accT
.getText());
344 XAccessibleComponent accC
=
345 UnoRuntime
.queryInterface(XAccessibleComponent
.class, oObj
);
346 System
.out
.println("BoundsX= "+accC
.getBounds().X
);
347 System
.out
.println("BoundsY= "+accC
.getBounds().Y
);
348 System
.out
.println("BoundsWidth= "+accC
.getBounds().Width
);
349 System
.out
.println("BoundsHeight= "+accC
.getBounds().Height
);
352 UnoRuntime
.queryInterface(XAccessibleComponent
.class, parent
);
354 System
.out
.println("Parent-BoundsX= "+accPC
.getBounds().X
);
355 System
.out
.println("Parent-BoundsY= "+accPC
.getBounds().Y
);
356 System
.out
.println("Parent-BoundsWidth= "+accPC
.getBounds().Width
);
357 System
.out
.println("Parent-BoundsHeight= "+accPC
.getBounds().Height
);
360 UnoRuntime
.queryInterface(XAccessibleComponent
.class,
361 parent
.getAccessibleContext().getAccessibleParent());
363 System
.out
.println("P-Parent-BoundsX= "+accPPC
.getBounds().X
);
364 System
.out
.println("P-Parent-BoundsY= "+accPPC
.getBounds().Y
);
365 System
.out
.println("P-Parent-BoundsWidth= "+accPPC
.getBounds().Width
);
366 System
.out
.println("P-Parent-BoundsHeight= "+accPPC
.getBounds().Height
);
370 System
.out
.println("Press any key when the footer is visible.");
372 byte[]b
= new byte[16];
374 } catch (Exception e
) {
379 parent
= AccessibilityTools
.getAccessibleObjectForRole
380 (xRoot
, AccessibleRole
.FOOTER
, "").getAccessibleChild(0);
381 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
382 fail(iabe
.getMessage());
387 UnoRuntime
.queryInterface(XAccessibleComponent
.class, parent
);
390 System
.out
.println("ChildCount: "+
391 parent
.getAccessibleContext().getAccessibleChildCount());
392 System
.out
.println("Getting child 0 again");
393 oObj
= parent
.getAccessibleContext().getAccessibleChild(0);
394 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
395 fail(iabe
.getMessage());
400 UnoRuntime
.queryInterface(XAccessibleText
.class, oObj
);
401 System
.out
.println("Getting the text: "+accT
.getText());
404 UnoRuntime
.queryInterface(XAccessibleComponent
.class, oObj
);
405 System
.out
.println("BoundsX= "+accC
.getBounds().X
);
406 System
.out
.println("BoundsY= "+accC
.getBounds().Y
);
407 System
.out
.println("BoundsWidth= "+accC
.getBounds().Width
);
408 System
.out
.println("BoundsHeight= "+accC
.getBounds().Height
);
411 UnoRuntime
.queryInterface(XAccessibleComponent
.class, parent
);
413 System
.out
.println("Parent-BoundsX= "+accPC
.getBounds().X
);
414 System
.out
.println("Parent-BoundsY= "+accPC
.getBounds().Y
);
415 System
.out
.println("Parent-BoundsWidth= "+accPC
.getBounds().Width
);
416 System
.out
.println("Parent-BoundsHeight= "+accPC
.getBounds().Height
);
419 UnoRuntime
.queryInterface(XAccessibleComponent
.class,
420 parent
.getAccessibleContext().getAccessibleParent());
422 System
.out
.println("P-Parent-BoundsX= "+accPPC
.getBounds().X
);
423 System
.out
.println("P-Parent-BoundsY= "+accPPC
.getBounds().Y
);
424 System
.out
.println("P-Parent-BoundsWidth= "+accPPC
.getBounds().Width
);
425 System
.out
.println("P-Parent-BoundsHeight= "+accPPC
.getBounds().Height
);
428 System
.out
.println("Press any key when the page content is on top");
430 byte[]b
= new byte[16];
432 } catch (Exception e
) {
437 parent
= AccessibilityTools
.getAccessibleObjectForRole
438 (xRoot
, AccessibleRole
.DOCUMENT
, "").getAccessibleChild(0);
439 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
440 fail(iabe
.getMessage());
443 System
.out
.println("PARENT: " + parent
.getAccessibleContext().getAccessibleName());
445 UnoRuntime
.queryInterface(XAccessibleComponent
.class, parent
);
450 parent
.getAccessibleContext().getAccessibleChildCount();
451 System
.out
.println("ChildCount: "+cCount
);
452 System
.out
.println("Getting child 0 again");
453 oObj
= parent
.getAccessibleContext().getAccessibleChild(0);
454 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
455 fail(iabe
.getMessage());
459 for (int i
=0; i
<cCount
; i
++) {
461 XAccessible xA
= parent
.getAccessibleContext().getAccessibleChild(i
);
462 System
.out
.println("NAME object " + i
+ ": " + xA
.getAccessibleContext().getAccessibleName());
463 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
464 fail(iabe
.getMessage());
469 System
.out
.println("SERVICES:");
470 util
.dbg
.getSuppServices(oObj
);
472 XAccessibleValue accV
=
473 UnoRuntime
.queryInterface(XAccessibleValue
.class, oObj
);
474 Object o
= accV
.getCurrentValue();
475 if (o
instanceof String
)
477 System
.out
.println("Value: " + (String
)o
);
481 System
.out
.println("Name of Object: " + o
.getClass().getName());
483 System
.out
.println("Getting the value: "+accV
.getCurrentValue());
489 UnoRuntime
.queryInterface(XAccessibleComponent
.class, oObj
);
490 System
.out
.println("BoundsX= "+accC
.getBounds().X
);
491 System
.out
.println("BoundsY= "+accC
.getBounds().Y
);
492 System
.out
.println("BoundsWidth= "+accC
.getBounds().Width
);
493 System
.out
.println("BoundsHeight= "+accC
.getBounds().Height
);
496 UnoRuntime
.queryInterface(XAccessibleComponent
.class, parent
);
498 System
.out
.println("Parent-BoundsX= "+accPC
.getBounds().X
);
499 System
.out
.println("Parent-BoundsY= "+accPC
.getBounds().Y
);
500 System
.out
.println("Parent-BoundsWidth= "+accPC
.getBounds().Width
);
501 System
.out
.println("Parent-BoundsHeight= "+accPC
.getBounds().Height
);
504 UnoRuntime
.queryInterface(XAccessibleComponent
.class,
505 parent
.getAccessibleContext().getAccessibleParent());
507 System
.out
.println("P-Parent-BoundsX= "+accPPC
.getBounds().X
);
508 System
.out
.println("P-Parent-BoundsY= "+accPPC
.getBounds().Y
);
509 System
.out
.println("P-Parent-BoundsWidth= "+accPPC
.getBounds().Width
);
510 System
.out
.println("P-Parent-BoundsHeight= "+accPPC
.getBounds().Height
);
512 XComponent xComp
= UnoRuntime
.queryInterface(
513 XComponent
.class, xSpreadsheetDoc
);
525 * Create a spreadsheet document, insert some text, header and footer.
526 * Let the user resize the document and check the contents.
528 @Test public void checkNegativeViewForwarder() {
529 SOfficeFactory SOF
= SOfficeFactory
.getFactory( mXMSF
);
530 XSpreadsheetDocument xSpreadsheetDoc
= null;
533 System
.out
.println("Creating a spreadsheet document");
534 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
535 } catch (com
.sun
.star
.uno
.Exception e
) {
536 fail(e
.getMessage());
540 XInterface oObj
= null;
542 // inserting some content to have non-empty page preview
545 XSpreadsheets oSheets
= xSpreadsheetDoc
.getSheets() ;
546 XIndexAccess oIndexSheets
=
547 UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
548 Object o
= oIndexSheets
.getByIndex(0);
549 XSpreadsheet oSheet
= (XSpreadsheet
)AnyConverter
.toObject(
550 new com
.sun
.star
.uno
.Type(XSpreadsheet
.class), o
);
551 xCell
= oSheet
.getCellByPosition(0, 0) ;
552 xCell
.setFormula("ScAccessiblePageHeader");
554 xCell
= oSheet
.getCellByPosition(0, 1) ;
555 xCell
.setFormula("Cell 1");
556 xCell
= oSheet
.getCellByPosition(0, 2) ;
557 xCell
.setFormula("Cell 2");
558 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
559 System
.out
.println("Exception ceating relation :");
560 fail(e
.getMessage());
561 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
562 System
.out
.println("Exception ceating relation :");
563 fail(e
.getMessage());
564 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
565 System
.out
.println("Exception ceating relation :");
566 fail(e
.getMessage());
570 UnoRuntime
.queryInterface(XModel
.class, xSpreadsheetDoc
);
572 XController xController
= aModel
.getCurrentController();
575 XStyleFamiliesSupplier StyleFam
=
576 UnoRuntime
.queryInterface(
577 XStyleFamiliesSupplier
.class,
579 XNameAccess StyleFamNames
= StyleFam
.getStyleFamilies();
580 XStyle StdStyle
= null;
583 Object o
= StyleFamNames
.getByName("PageStyles");
584 XNameAccess PageStyles
= (XNameAccess
)AnyConverter
.toObject(
585 new com
.sun
.star
.uno
.Type(XNameAccess
.class), o
);
587 o
= PageStyles
.getByName("Default");
588 StdStyle
= (XStyle
)AnyConverter
.toObject(
589 new com
.sun
.star
.uno
.Type(XStyle
.class), o
);
590 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
591 fail(e
.getMessage());
592 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
593 fail(e
.getMessage());
595 } catch(com
.sun
.star
.container
.NoSuchElementException e
){
596 fail(e
.getMessage());
600 //get the property-set
601 final XPropertySet PropSet
=
602 UnoRuntime
.queryInterface(XPropertySet
.class, StdStyle
);
604 XHeaderFooterContent RPHFC
= null;
607 System
.out
.println( "Creating a test environment" );
609 Object o
= PropSet
.getPropertyValue("RightPageHeaderContent");
610 RPHFC
= (XHeaderFooterContent
)AnyConverter
.toObject(
611 new com
.sun
.star
.uno
.Type(XHeaderFooterContent
.class), o
);
612 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
613 fail(e
.getMessage());
614 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
615 fail(e
.getMessage());
617 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
){
618 fail(e
.getMessage());
622 // insert text into header
623 XText center
= RPHFC
.getCenterText();
624 center
.setString("First line \n\r Second line \n\r third line ");
626 PropSet
.setPropertyValue("RightPageHeaderContent",RPHFC
);
627 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
628 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
629 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
630 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {}
635 Object o
= PropSet
.getPropertyValue("RightPageFooterContent");
636 RPHFC
= (XHeaderFooterContent
)AnyConverter
.toObject(
637 new com
.sun
.star
.uno
.Type(XHeaderFooterContent
.class), o
);
638 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
639 fail(e
.getMessage());
640 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
641 fail(e
.getMessage());
643 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
){
644 fail(e
.getMessage());
648 // insert text into footer
649 center
= RPHFC
.getCenterText();
650 center
.setString("Third last line\n\r Second last line\n\r last line");
652 PropSet
.setPropertyValue("RightPageFooterContent",RPHFC
);
653 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
654 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
655 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
656 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {}
658 // switching to 'Page Preview' mode
660 XDispatchProvider xDispProv
=
661 UnoRuntime
.queryInterface(XDispatchProvider
.class, xController
);
662 XURLTransformer xParser
=
663 UnoRuntime
.queryInterface(XURLTransformer
.class,
664 mXMSF
.createInstance("com.sun.star.util.URLTransformer"));
665 // Because it's an in/out parameter we must use an
666 // array of URL objects.
667 URL
[] aParseURL
= new URL
[1];
668 aParseURL
[0] = new URL();
669 aParseURL
[0].Complete
= ".uno:PrintPreview";
670 xParser
.parseStrict(aParseURL
);
671 URL aURL
= aParseURL
[0];
672 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
673 if(xDispatcher
!= null)
675 xDispatcher
.dispatch( aURL
, null );
677 } catch (com
.sun
.star
.uno
.Exception e
) {
678 fail("Couldn't change mode");
684 } catch (InterruptedException ex
) {}
686 System
.out
.println("Press any key after resizing ");
688 byte[]b
= new byte[16];
690 } catch (Exception e
) {
694 // get the accessible content
695 AccessibilityTools at
= new AccessibilityTools();
697 XWindow xWindow
= AccessibilityTools
.getCurrentWindow(mXMSF
, aModel
);
698 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
699 XAccessible parent
= null;
702 parent
= AccessibilityTools
.getAccessibleObjectForRole
703 (xRoot
, AccessibleRole
.HEADER
, "").getAccessibleChild(0);
704 oObj
= parent
.getAccessibleContext().getAccessibleChild(0);
705 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
706 fail(iabe
.getMessage());
710 System
.out
.println("ImplementationName " + utils
.getImplName(oObj
));
712 XAccessibleComponent accPC
=
713 UnoRuntime
.queryInterface(XAccessibleComponent
.class, parent
);
715 System
.out
.println("Parent-BoundsX= "+accPC
.getBounds().X
);
716 System
.out
.println("Parent-BoundsY= "+accPC
.getBounds().Y
);
717 System
.out
.println("Parent-BoundsWidth= "+accPC
.getBounds().Width
);
718 System
.out
.println("Parent-BoundsHeight= "+accPC
.getBounds().Height
);
720 XAccessibleComponent accPPC
=
721 UnoRuntime
.queryInterface(XAccessibleComponent
.class,
722 parent
.getAccessibleContext().getAccessibleParent());
724 System
.out
.println("P-Parent-BoundsX= "+accPPC
.getBounds().X
);
725 System
.out
.println("P-Parent-BoundsY= "+accPPC
.getBounds().Y
);
726 System
.out
.println("P-Parent-BoundsWidth= "+accPPC
.getBounds().Width
);
727 System
.out
.println("P-Parent-BoundsHeight= "+accPPC
.getBounds().Height
);
731 } catch (InterruptedException ex
) {}
733 System
.out
.println("Press any key when the header is not visible.");
735 byte[]b
= new byte[16];
737 } catch (Exception e
) {
743 parent
.getAccessibleContext().getAccessibleChildCount();
744 System
.out
.println("ChildCount: "+childCount
);
748 fail("Could access header although it was not visible on page.");
753 parent
= AccessibilityTools
.getAccessibleObjectForRole
754 (xRoot
, AccessibleRole
.FOOTER
, "").getAccessibleChild(0);
755 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
756 fail(iabe
.getMessage());
761 UnoRuntime
.queryInterface(XAccessibleComponent
.class, parent
);
763 System
.out
.println("Press any key when the footer is not visible.");
765 byte[]b
= new byte[16];
767 } catch (Exception e
) {
772 parent
.getAccessibleContext().getAccessibleChildCount();
773 System
.out
.println("ChildCount: "+childCount
);
777 fail("Could access footer although it was not visible on page.");
780 XComponent xComp
=UnoRuntime
.queryInterface(
781 XComponent
.class, xSpreadsheetDoc
);
790 * Check the preview of header cells
792 @Test public void checkPreviewHeaderCells() {
794 XInterface oObj
= null;
795 SOfficeFactory SOF
= SOfficeFactory
.getFactory( mXMSF
);
796 XSpreadsheetDocument xSpreadsheetDoc
= null;
799 System
.out
.println("Creating a spreadsheet document");
800 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
801 } catch (com
.sun
.star
.uno
.Exception e
) {
802 fail(e
.getMessage());
807 UnoRuntime
.queryInterface(XModel
.class, xSpreadsheetDoc
);
809 XController xController
= xModel
.getCurrentController();
811 //setting value of cell A1
814 System
.out
.println("Getting spreadsheet") ;
815 XSpreadsheets oSheets
= xSpreadsheetDoc
.getSheets() ;
816 XIndexAccess oIndexSheets
=
817 UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
818 Object o
= oIndexSheets
.getByIndex(0);
819 XSpreadsheet oSheet
= (XSpreadsheet
)AnyConverter
.toObject(
820 new com
.sun
.star
.uno
.Type(XSpreadsheet
.class), o
);
822 System
.out
.println("Getting a cell from sheet") ;
823 xCell
= oSheet
.getCellByPosition(0, 0);
824 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
825 fail(e
.getMessage());
826 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
827 fail(e
.getMessage());
829 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
830 fail(e
.getMessage());
834 xCell
.setFormula("Value");
836 //setting property 'PrintHeaders' of the style 'Default'
837 XStyleFamiliesSupplier xSFS
=
838 UnoRuntime
.queryInterface(XStyleFamiliesSupplier
.class,
840 XNameAccess xNA
= xSFS
.getStyleFamilies();
841 XPropertySet xPropSet
= null;
843 Object oPageStyles
= xNA
.getByName("PageStyles");
845 UnoRuntime
.queryInterface(XNameAccess
.class, oPageStyles
);
846 Object oDefStyle
= xNA
.getByName("Default");
848 UnoRuntime
.queryInterface(XPropertySet
.class, oDefStyle
);
849 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
850 fail(e
.getMessage());
852 } catch(com
.sun
.star
.container
.NoSuchElementException e
) {
853 fail(e
.getMessage());
858 xPropSet
.setPropertyValue("PrintHeaders", new Boolean(true));
859 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
860 fail(e
.getMessage());
862 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
863 fail(e
.getMessage());
865 } catch(com
.sun
.star
.beans
.PropertyVetoException e
) {
866 fail(e
.getMessage());
868 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
869 fail(e
.getMessage());
873 //switching to 'Print Preview' mode
875 XDispatchProvider xDispProv
=
876 UnoRuntime
.queryInterface(XDispatchProvider
.class, xController
);
877 XURLTransformer xParser
=
878 UnoRuntime
.queryInterface(XURLTransformer
.class,
879 mXMSF
.createInstance("com.sun.star.util.URLTransformer"));
880 URL
[] aParseURL
= new URL
[1];
881 aParseURL
[0] = new URL();
882 aParseURL
[0].Complete
= ".uno:PrintPreview";
883 xParser
.parseStrict(aParseURL
);
884 URL aURL
= aParseURL
[0];
885 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
886 if(xDispatcher
!= null)
888 xDispatcher
.dispatch( aURL
, null );
890 } catch (com
.sun
.star
.uno
.Exception e
) {
891 fail(e
.getMessage());
897 } catch (InterruptedException e
) {
898 System
.out
.println("While waiting :" + e
) ;
901 AccessibilityTools at
= new AccessibilityTools();
903 XWindow xWindow
= AccessibilityTools
.getCurrentWindow(mXMSF
, xModel
);
904 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
906 // System.out.println("ImplementationName " + utils.getImplName(oObj));
908 System
.out
.println("Press any key when the header cell is on top.");
910 byte[]b
= new byte[16];
912 } catch (Exception e
) {
917 XAccessible parent
= null;
920 System
.out
.println("Count: " +AccessibilityTools
.getAccessibleObjectForRole
921 (xRoot
, AccessibleRole
.TABLE
, "").getAccessibleChildCount());
922 // parent = at.getAccessibleObjectForRole
923 // (xRoot, AccessibleRole.TABLE, "").getAccessibleChild(0);
924 // oObj = parent.getAccessibleContext().getAccessibleChild(1);
925 System
.out
.println("Getting child 2");
926 oObj
= AccessibilityTools
.getAccessibleObjectForRole
927 (xRoot
, AccessibleRole
.TABLE
, "").getAccessibleChild(2);
928 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
929 fail(iabe
.getMessage());
933 System
.out
.println("*** DEBUG INFO ***");
934 util
.dbg
.getSuppServices(oObj
);
935 System
.out
.println("****** IFC ******");
936 util
.dbg
.printInterfaces(oObj
);
937 System
.out
.println("*****************");
940 /* XAccessibleContext accCtx = (XAccessibleContext)
941 UnoRuntime.queryInterface(XAccessibleContext.class, oObj);
943 System.out.println("Children now: " + accCtx.getAccessibleChild(0).getAccessibleContext().getAccessibleChildCount());
944 } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
945 fail(iabe.getMessage());
950 XAccessibleValue accV
=
951 UnoRuntime
.queryInterface(XAccessibleValue
.class, oObj
);
952 Object o
= accV
.getCurrentValue();
953 System
.out
.println("Getting the value: "+o
+ " is void " + util
.utils
.isVoid(o
));
956 XAccessibleComponent accC
=
957 UnoRuntime
.queryInterface(XAccessibleComponent
.class, oObj
);
959 System
.out
.println("BoundsX= "+accC
.getBounds().X
);
960 System
.out
.println("BoundsY= "+accC
.getBounds().Y
);
961 System
.out
.println("BoundsWidth= "+accC
.getBounds().Width
);
962 System
.out
.println("BoundsHeight= "+accC
.getBounds().Height
);
964 XComponent xComp
= UnoRuntime
.queryInterface(
965 XComponent
.class, xSpreadsheetDoc
);
975 * Check the preview of Shapes: load a document with shapes and see, if they
978 @Test public void checkPreviewShape() {
979 SOfficeFactory SOF
= SOfficeFactory
.getFactory( mXMSF
);
980 XSpreadsheetDocument xSpreadsheetDoc
= null;
981 XComponent xComp
= null;
982 XInterface oObj
= null;
985 String docName
= "calcshapes.sxc";
986 System
.out
.println("Loading a spreadsheetdocument.");
987 // String url = utils.getFullURL((String)param.get("TestDocumentPath") + "/" + docName);
988 String url
= TestDocument
.getUrl(docName
);
989 System
.out
.println("loading document '" + url
+ "'");
990 xComp
= SOF
.loadDocument(url
);
991 assertNotNull(xComp
);
993 catch (com
.sun
.star
.uno
.Exception e
) {
994 fail(e
.getMessage());
1000 } catch (InterruptedException e
) {
1001 System
.out
.println("While waiting :" + e
) ;
1004 if (xComp
== null) {
1005 fail("loading document failed.");
1009 xSpreadsheetDoc
= UnoRuntime
.queryInterface(
1010 XSpreadsheetDocument
.class, xComp
);
1012 UnoRuntime
.queryInterface(XModel
.class, xSpreadsheetDoc
);
1014 XController xController
= aModel
.getCurrentController();
1016 // switching to 'Page Preview' mode
1018 XDispatchProvider xDispProv
=
1019 UnoRuntime
.queryInterface(XDispatchProvider
.class, xController
);
1020 XURLTransformer xParser
=
1021 UnoRuntime
.queryInterface(XURLTransformer
.class,
1022 mXMSF
.createInstance("com.sun.star.util.URLTransformer"));
1023 // Because it's an in/out parameter we must use an
1024 // array of URL objects.
1025 URL
[] aParseURL
= new URL
[1];
1026 aParseURL
[0] = new URL();
1027 aParseURL
[0].Complete
= ".uno:PrintPreview";
1028 xParser
.parseStrict(aParseURL
);
1029 URL aURL
= aParseURL
[0];
1030 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
1031 if(xDispatcher
!= null)
1033 xDispatcher
.dispatch( aURL
, null );
1035 } catch (com
.sun
.star
.uno
.Exception e
) {
1036 fail("Couldn't change mode");
1042 } catch (InterruptedException e
) {
1043 System
.out
.println("While waiting :" + e
) ;
1048 System
.out
.println("Press any key when a shape is on top.");
1050 byte[]b
= new byte[16];
1052 } catch (Exception e
) {
1053 e
.printStackTrace();
1056 // get the accessible content
1057 AccessibilityTools at
= new AccessibilityTools();
1059 XWindow xWindow
= AccessibilityTools
.getCurrentWindow(mXMSF
, aModel
);
1060 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
1061 XAccessible parent
= null;
1064 XAccessibleContext con
= AccessibilityTools
.getAccessibleObjectForRole
1065 (xRoot
, AccessibleRole
.SHAPE
, "");
1066 System
.out
.println("Name of AccessibleContext: " + con
.getAccessibleName());
1068 } catch (Exception e
) {
1069 fail(e
.getMessage());
1073 System
.out
.println("ImplementationName: " + utils
.getImplName(oObj
));
1074 util
.dbg
.printInterfaces(oObj
);
1079 @BeforeClass public static void setUpConnection() throws Exception
{
1083 @AfterClass public static void tearDownConnection()
1084 throws InterruptedException
, com
.sun
.star
.uno
.Exception
1086 connection
.tearDown();
1089 private static final OfficeConnection connection
= new OfficeConnection();