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 com
.sun
.star
.awt
.XWindow
;
22 import com
.sun
.star
.container
.XIndexAccess
;
23 import com
.sun
.star
.frame
.XController
;
24 import com
.sun
.star
.frame
.XDispatch
;
25 import com
.sun
.star
.frame
.XDispatchProvider
;
26 import com
.sun
.star
.frame
.XModel
;
27 import com
.sun
.star
.lang
.XMultiServiceFactory
;
28 import com
.sun
.star
.sheet
.XSpreadsheet
;
29 import com
.sun
.star
.sheet
.XSpreadsheets
;
30 import com
.sun
.star
.table
.XCell
;
31 import com
.sun
.star
.uno
.AnyConverter
;
32 import com
.sun
.star
.uno
.UnoRuntime
;
33 import com
.sun
.star
.uno
.XInterface
;
34 import com
.sun
.star
.util
.URL
;
35 import com
.sun
.star
.util
.XURLTransformer
;
36 import com
.sun
.star
.accessibility
.AccessibleRole
;
37 import com
.sun
.star
.accessibility
.XAccessible
;
38 import com
.sun
.star
.accessibility
.XAccessibleText
;
39 import com
.sun
.star
.accessibility
.XAccessibleValue
;
40 import com
.sun
.star
.accessibility
.XAccessibleComponent
;
41 import com
.sun
.star
.accessibility
.XAccessibleContext
;
43 import util
.AccessibilityTools
;
44 import util
.SOfficeFactory
;
47 import com
.sun
.star
.beans
.XPropertySet
;
48 import com
.sun
.star
.container
.XNameAccess
;
49 import com
.sun
.star
.lang
.XComponent
;
50 import com
.sun
.star
.sheet
.XHeaderFooterContent
;
51 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
52 import com
.sun
.star
.style
.XStyle
;
53 import com
.sun
.star
.style
.XStyleFamiliesSupplier
;
54 import com
.sun
.star
.text
.XText
;
56 import org
.junit
.AfterClass
;
57 import org
.junit
.Before
;
58 import org
.junit
.BeforeClass
;
59 import org
.junit
.Test
;
60 import org
.openoffice
.test
.OfficeConnection
;
61 import static org
.junit
.Assert
.*;
64 * A complex test for the preview of Calc documents. This complex test
65 * needs interaction from the user: documents have to be resized and moved.
67 public class ViewForwarder
{
69 /** The MultiServiceFactory **/
70 private XMultiServiceFactory mXMSF
= null;
73 * Get a MultiServiceFactory from the Office before the test.
75 @Before public void before()
77 mXMSF
= UnoRuntime
.queryInterface(XMultiServiceFactory
.class, connection
.getComponentContext().getServiceManager());
81 /** Create a spreadsheet document, insert some text, header and footer.
82 * Let the user resize the document and check the contents.
84 @Test public void checkPositiveViewForwarder() {
85 SOfficeFactory SOF
= SOfficeFactory
.getFactory( mXMSF
);
86 XSpreadsheetDocument xSpreadsheetDoc
= null;
89 System
.out
.println("Creating a spreadsheet document");
90 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
91 } catch (com
.sun
.star
.uno
.Exception e
) {
96 XInterface oObj
= null;
98 // inserting some content to have non-empty page preview
101 XSpreadsheets oSheets
= xSpreadsheetDoc
.getSheets() ;
102 XIndexAccess oIndexSheets
=
103 UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
104 Object o
= oIndexSheets
.getByIndex(0);
105 XSpreadsheet oSheet
= (XSpreadsheet
)AnyConverter
.toObject(
106 new com
.sun
.star
.uno
.Type(XSpreadsheet
.class), o
);
107 xCell
= oSheet
.getCellByPosition(0, 0) ;
108 xCell
.setFormula("ScAccessiblePageHeader");
110 xCell
= oSheet
.getCellByPosition(0, 1) ;
111 xCell
.setFormula("Cell 1");
112 xCell
= oSheet
.getCellByPosition(0, 2) ;
113 xCell
.setFormula("Cell 2");
114 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
115 System
.out
.println("Exception ceating relation :");
116 fail(e
.getMessage());
117 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
118 System
.out
.println("Exception ceating relation :");
119 fail(e
.getMessage());
120 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
121 System
.out
.println("Exception ceating relation :");
122 fail(e
.getMessage());
126 UnoRuntime
.queryInterface(XModel
.class, xSpreadsheetDoc
);
128 XController xController
= aModel
.getCurrentController();
131 XStyleFamiliesSupplier StyleFam
=
132 UnoRuntime
.queryInterface(
133 XStyleFamiliesSupplier
.class,
135 XNameAccess StyleFamNames
= StyleFam
.getStyleFamilies();
136 XStyle StdStyle
= null;
139 Object o
= StyleFamNames
.getByName("PageStyles");
140 XNameAccess PageStyles
= (XNameAccess
)AnyConverter
.toObject(
141 new com
.sun
.star
.uno
.Type(XNameAccess
.class), o
);
143 o
= PageStyles
.getByName("Default");
144 StdStyle
= (XStyle
)AnyConverter
.toObject(
145 new com
.sun
.star
.uno
.Type(XStyle
.class), o
);
146 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
147 fail(e
.getMessage());
148 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
149 fail(e
.getMessage());
151 } catch(com
.sun
.star
.container
.NoSuchElementException e
){
152 fail(e
.getMessage());
156 //get the property-set
157 final XPropertySet PropSet
=
158 UnoRuntime
.queryInterface(XPropertySet
.class, StdStyle
);
160 XHeaderFooterContent RPHFC
= null;
164 Object o
= PropSet
.getPropertyValue("RightPageHeaderContent");
165 RPHFC
= (XHeaderFooterContent
)AnyConverter
.toObject(
166 new com
.sun
.star
.uno
.Type(XHeaderFooterContent
.class), o
);
168 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
169 fail(e
.getMessage());
170 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
171 fail(e
.getMessage());
173 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
){
174 fail(e
.getMessage());
178 // insert text into header
179 XText center
= RPHFC
.getCenterText();
180 center
.setString("First line \n\r Second line \n\r third line ");
182 PropSet
.setPropertyValue("RightPageHeaderContent",RPHFC
);
183 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
184 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
185 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
186 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {}
191 Object o
= PropSet
.getPropertyValue("RightPageHeaderContent");
192 RPHFC
= (XHeaderFooterContent
)AnyConverter
.toObject(
193 new com
.sun
.star
.uno
.Type(XHeaderFooterContent
.class), o
);
194 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
195 fail(e
.getMessage());
196 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
197 fail(e
.getMessage());
199 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
){
200 fail(e
.getMessage());
204 // insert text into footer
205 center
= RPHFC
.getCenterText();
206 center
.setString("Third last line\n\r Second last line\n\r last line");
208 PropSet
.setPropertyValue("RightPageFooterContent",RPHFC
);
209 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
210 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
211 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
212 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {}
214 // switching to 'Page Preview' mode
216 XDispatchProvider xDispProv
=
217 UnoRuntime
.queryInterface(XDispatchProvider
.class, xController
);
218 XURLTransformer xParser
=
219 UnoRuntime
.queryInterface(XURLTransformer
.class,
220 mXMSF
.createInstance("com.sun.star.util.URLTransformer"));
221 // Because it's an in/out parameter we must use an
222 // array of URL objects.
223 URL
[] aParseURL
= new URL
[1];
224 aParseURL
[0] = new URL();
225 aParseURL
[0].Complete
= ".uno:PrintPreview";
226 xParser
.parseStrict(aParseURL
);
227 URL aURL
= aParseURL
[0];
228 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
229 if(xDispatcher
!= null)
231 xDispatcher
.dispatch( aURL
, null );
233 } catch (com
.sun
.star
.uno
.Exception e
) {
234 fail("Couldn't change mode");
238 util
.utils
.pause(500);
240 System
.out
.println("Press any key after resizing ");
242 byte[]b
= new byte[16];
244 } catch (Exception e
) {
248 XWindow xWindow
= AccessibilityTools
.getCurrentWindow(aModel
);
249 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
250 XAccessible parent
= null;
253 parent
= AccessibilityTools
.getAccessibleObjectForRole
254 (xRoot
, AccessibleRole
.HEADER
, "").getAccessibleChild(0);
255 oObj
= parent
.getAccessibleContext().getAccessibleChild(0);
256 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
257 fail(iabe
.getMessage());
261 System
.out
.println("ImplementationName " + utils
.getImplName(oObj
));
263 XAccessibleComponent accPC
=
264 UnoRuntime
.queryInterface(XAccessibleComponent
.class, parent
);
266 System
.out
.println("Parent-BoundsX= "+accPC
.getBounds().X
);
267 System
.out
.println("Parent-BoundsY= "+accPC
.getBounds().Y
);
268 System
.out
.println("Parent-BoundsWidth= "+accPC
.getBounds().Width
);
269 System
.out
.println("Parent-BoundsHeight= "+accPC
.getBounds().Height
);
271 XAccessibleComponent accPPC
=
272 UnoRuntime
.queryInterface(XAccessibleComponent
.class,
273 parent
.getAccessibleContext().getAccessibleParent());
275 System
.out
.println("P-Parent-BoundsX= "+accPPC
.getBounds().X
);
276 System
.out
.println("P-Parent-BoundsY= "+accPPC
.getBounds().Y
);
277 System
.out
.println("P-Parent-BoundsWidth= "+accPPC
.getBounds().Width
);
278 System
.out
.println("P-Parent-BoundsHeight= "+accPPC
.getBounds().Height
);
280 util
.utils
.pause(500);
282 System
.out
.println("Press any key when the second line is on top");
284 byte[]b
= new byte[16];
286 } catch (Exception e
) {
291 System
.out
.println("ChildCount: "+
292 parent
.getAccessibleContext().getAccessibleChildCount());
293 System
.out
.println("Getting child 0 again");
294 oObj
= parent
.getAccessibleContext().getAccessibleChild(0);
295 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
296 fail(iabe
.getMessage());
300 XAccessibleText accT
=
301 UnoRuntime
.queryInterface(XAccessibleText
.class, oObj
);
302 System
.out
.println("Getting the text: "+accT
.getText());
304 XAccessibleComponent accC
=
305 UnoRuntime
.queryInterface(XAccessibleComponent
.class, oObj
);
306 System
.out
.println("BoundsX= "+accC
.getBounds().X
);
307 System
.out
.println("BoundsY= "+accC
.getBounds().Y
);
308 System
.out
.println("BoundsWidth= "+accC
.getBounds().Width
);
309 System
.out
.println("BoundsHeight= "+accC
.getBounds().Height
);
312 UnoRuntime
.queryInterface(XAccessibleComponent
.class, parent
);
314 System
.out
.println("Parent-BoundsX= "+accPC
.getBounds().X
);
315 System
.out
.println("Parent-BoundsY= "+accPC
.getBounds().Y
);
316 System
.out
.println("Parent-BoundsWidth= "+accPC
.getBounds().Width
);
317 System
.out
.println("Parent-BoundsHeight= "+accPC
.getBounds().Height
);
320 UnoRuntime
.queryInterface(XAccessibleComponent
.class,
321 parent
.getAccessibleContext().getAccessibleParent());
323 System
.out
.println("P-Parent-BoundsX= "+accPPC
.getBounds().X
);
324 System
.out
.println("P-Parent-BoundsY= "+accPPC
.getBounds().Y
);
325 System
.out
.println("P-Parent-BoundsWidth= "+accPPC
.getBounds().Width
);
326 System
.out
.println("P-Parent-BoundsHeight= "+accPPC
.getBounds().Height
);
330 System
.out
.println("Press any key when the footer is visible.");
332 byte[]b
= new byte[16];
334 } catch (Exception e
) {
339 parent
= AccessibilityTools
.getAccessibleObjectForRole
340 (xRoot
, AccessibleRole
.FOOTER
, "").getAccessibleChild(0);
341 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
342 fail(iabe
.getMessage());
347 UnoRuntime
.queryInterface(XAccessibleComponent
.class, parent
);
350 System
.out
.println("ChildCount: "+
351 parent
.getAccessibleContext().getAccessibleChildCount());
352 System
.out
.println("Getting child 0 again");
353 oObj
= parent
.getAccessibleContext().getAccessibleChild(0);
354 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
355 fail(iabe
.getMessage());
360 UnoRuntime
.queryInterface(XAccessibleText
.class, oObj
);
361 System
.out
.println("Getting the text: "+accT
.getText());
364 UnoRuntime
.queryInterface(XAccessibleComponent
.class, oObj
);
365 System
.out
.println("BoundsX= "+accC
.getBounds().X
);
366 System
.out
.println("BoundsY= "+accC
.getBounds().Y
);
367 System
.out
.println("BoundsWidth= "+accC
.getBounds().Width
);
368 System
.out
.println("BoundsHeight= "+accC
.getBounds().Height
);
371 UnoRuntime
.queryInterface(XAccessibleComponent
.class, parent
);
373 System
.out
.println("Parent-BoundsX= "+accPC
.getBounds().X
);
374 System
.out
.println("Parent-BoundsY= "+accPC
.getBounds().Y
);
375 System
.out
.println("Parent-BoundsWidth= "+accPC
.getBounds().Width
);
376 System
.out
.println("Parent-BoundsHeight= "+accPC
.getBounds().Height
);
379 UnoRuntime
.queryInterface(XAccessibleComponent
.class,
380 parent
.getAccessibleContext().getAccessibleParent());
382 System
.out
.println("P-Parent-BoundsX= "+accPPC
.getBounds().X
);
383 System
.out
.println("P-Parent-BoundsY= "+accPPC
.getBounds().Y
);
384 System
.out
.println("P-Parent-BoundsWidth= "+accPPC
.getBounds().Width
);
385 System
.out
.println("P-Parent-BoundsHeight= "+accPPC
.getBounds().Height
);
388 System
.out
.println("Press any key when the page content is on top");
390 byte[]b
= new byte[16];
392 } catch (Exception e
) {
397 parent
= AccessibilityTools
.getAccessibleObjectForRole
398 (xRoot
, AccessibleRole
.DOCUMENT
, "").getAccessibleChild(0);
399 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
400 fail(iabe
.getMessage());
403 System
.out
.println("PARENT: " + parent
.getAccessibleContext().getAccessibleName());
405 UnoRuntime
.queryInterface(XAccessibleComponent
.class, parent
);
410 parent
.getAccessibleContext().getAccessibleChildCount();
411 System
.out
.println("ChildCount: "+cCount
);
412 System
.out
.println("Getting child 0 again");
413 oObj
= parent
.getAccessibleContext().getAccessibleChild(0);
414 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
415 fail(iabe
.getMessage());
419 for (int i
=0; i
<cCount
; i
++) {
421 XAccessible xA
= parent
.getAccessibleContext().getAccessibleChild(i
);
422 System
.out
.println("NAME object " + i
+ ": " + xA
.getAccessibleContext().getAccessibleName());
423 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
424 fail(iabe
.getMessage());
429 System
.out
.println("SERVICES:");
430 util
.dbg
.getSuppServices(oObj
);
432 XAccessibleValue accV
=
433 UnoRuntime
.queryInterface(XAccessibleValue
.class, oObj
);
434 Object o
= accV
.getCurrentValue();
435 if (o
instanceof String
)
437 System
.out
.println("Value: " + (String
)o
);
441 System
.out
.println("Name of Object: " + o
.getClass().getName());
443 System
.out
.println("Getting the value: "+accV
.getCurrentValue());
449 UnoRuntime
.queryInterface(XAccessibleComponent
.class, oObj
);
450 System
.out
.println("BoundsX= "+accC
.getBounds().X
);
451 System
.out
.println("BoundsY= "+accC
.getBounds().Y
);
452 System
.out
.println("BoundsWidth= "+accC
.getBounds().Width
);
453 System
.out
.println("BoundsHeight= "+accC
.getBounds().Height
);
456 UnoRuntime
.queryInterface(XAccessibleComponent
.class, parent
);
458 System
.out
.println("Parent-BoundsX= "+accPC
.getBounds().X
);
459 System
.out
.println("Parent-BoundsY= "+accPC
.getBounds().Y
);
460 System
.out
.println("Parent-BoundsWidth= "+accPC
.getBounds().Width
);
461 System
.out
.println("Parent-BoundsHeight= "+accPC
.getBounds().Height
);
464 UnoRuntime
.queryInterface(XAccessibleComponent
.class,
465 parent
.getAccessibleContext().getAccessibleParent());
467 System
.out
.println("P-Parent-BoundsX= "+accPPC
.getBounds().X
);
468 System
.out
.println("P-Parent-BoundsY= "+accPPC
.getBounds().Y
);
469 System
.out
.println("P-Parent-BoundsWidth= "+accPPC
.getBounds().Width
);
470 System
.out
.println("P-Parent-BoundsHeight= "+accPPC
.getBounds().Height
);
472 XComponent xComp
= UnoRuntime
.queryInterface(
473 XComponent
.class, xSpreadsheetDoc
);
485 * Create a spreadsheet document, insert some text, header and footer.
486 * Let the user resize the document and check the contents.
488 @Test public void checkNegativeViewForwarder() {
489 SOfficeFactory SOF
= SOfficeFactory
.getFactory( mXMSF
);
490 XSpreadsheetDocument xSpreadsheetDoc
= null;
493 System
.out
.println("Creating a spreadsheet document");
494 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
495 } catch (com
.sun
.star
.uno
.Exception e
) {
496 fail(e
.getMessage());
500 XInterface oObj
= null;
502 // inserting some content to have non-empty page preview
505 XSpreadsheets oSheets
= xSpreadsheetDoc
.getSheets() ;
506 XIndexAccess oIndexSheets
=
507 UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
508 Object o
= oIndexSheets
.getByIndex(0);
509 XSpreadsheet oSheet
= (XSpreadsheet
)AnyConverter
.toObject(
510 new com
.sun
.star
.uno
.Type(XSpreadsheet
.class), o
);
511 xCell
= oSheet
.getCellByPosition(0, 0) ;
512 xCell
.setFormula("ScAccessiblePageHeader");
514 xCell
= oSheet
.getCellByPosition(0, 1) ;
515 xCell
.setFormula("Cell 1");
516 xCell
= oSheet
.getCellByPosition(0, 2) ;
517 xCell
.setFormula("Cell 2");
518 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
519 System
.out
.println("Exception ceating relation :");
520 fail(e
.getMessage());
521 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
522 System
.out
.println("Exception ceating relation :");
523 fail(e
.getMessage());
524 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
525 System
.out
.println("Exception ceating relation :");
526 fail(e
.getMessage());
530 UnoRuntime
.queryInterface(XModel
.class, xSpreadsheetDoc
);
532 XController xController
= aModel
.getCurrentController();
535 XStyleFamiliesSupplier StyleFam
=
536 UnoRuntime
.queryInterface(
537 XStyleFamiliesSupplier
.class,
539 XNameAccess StyleFamNames
= StyleFam
.getStyleFamilies();
540 XStyle StdStyle
= null;
543 Object o
= StyleFamNames
.getByName("PageStyles");
544 XNameAccess PageStyles
= (XNameAccess
)AnyConverter
.toObject(
545 new com
.sun
.star
.uno
.Type(XNameAccess
.class), o
);
547 o
= PageStyles
.getByName("Default");
548 StdStyle
= (XStyle
)AnyConverter
.toObject(
549 new com
.sun
.star
.uno
.Type(XStyle
.class), o
);
550 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
551 fail(e
.getMessage());
552 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
553 fail(e
.getMessage());
555 } catch(com
.sun
.star
.container
.NoSuchElementException e
){
556 fail(e
.getMessage());
560 //get the property-set
561 final XPropertySet PropSet
=
562 UnoRuntime
.queryInterface(XPropertySet
.class, StdStyle
);
564 XHeaderFooterContent RPHFC
= null;
567 System
.out
.println( "Creating a test environment" );
569 Object o
= PropSet
.getPropertyValue("RightPageHeaderContent");
570 RPHFC
= (XHeaderFooterContent
)AnyConverter
.toObject(
571 new com
.sun
.star
.uno
.Type(XHeaderFooterContent
.class), o
);
572 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
573 fail(e
.getMessage());
574 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
575 fail(e
.getMessage());
577 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
){
578 fail(e
.getMessage());
582 // insert text into header
583 XText center
= RPHFC
.getCenterText();
584 center
.setString("First line \n\r Second line \n\r third line ");
586 PropSet
.setPropertyValue("RightPageHeaderContent",RPHFC
);
587 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
588 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
589 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
590 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {}
595 Object o
= PropSet
.getPropertyValue("RightPageFooterContent");
596 RPHFC
= (XHeaderFooterContent
)AnyConverter
.toObject(
597 new com
.sun
.star
.uno
.Type(XHeaderFooterContent
.class), o
);
598 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
599 fail(e
.getMessage());
600 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
601 fail(e
.getMessage());
603 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
){
604 fail(e
.getMessage());
608 // insert text into footer
609 center
= RPHFC
.getCenterText();
610 center
.setString("Third last line\n\r Second last line\n\r last line");
612 PropSet
.setPropertyValue("RightPageFooterContent",RPHFC
);
613 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
614 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
615 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
616 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {}
618 // switching to 'Page Preview' mode
620 XDispatchProvider xDispProv
=
621 UnoRuntime
.queryInterface(XDispatchProvider
.class, xController
);
622 XURLTransformer xParser
=
623 UnoRuntime
.queryInterface(XURLTransformer
.class,
624 mXMSF
.createInstance("com.sun.star.util.URLTransformer"));
625 // Because it's an in/out parameter we must use an
626 // array of URL objects.
627 URL
[] aParseURL
= new URL
[1];
628 aParseURL
[0] = new URL();
629 aParseURL
[0].Complete
= ".uno:PrintPreview";
630 xParser
.parseStrict(aParseURL
);
631 URL aURL
= aParseURL
[0];
632 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
633 if(xDispatcher
!= null)
635 xDispatcher
.dispatch( aURL
, null );
637 } catch (com
.sun
.star
.uno
.Exception e
) {
638 fail("Couldn't change mode");
642 util
.utils
.pause(500);
644 System
.out
.println("Press any key after resizing ");
646 byte[]b
= new byte[16];
648 } catch (Exception e
) {
652 XWindow xWindow
= AccessibilityTools
.getCurrentWindow(aModel
);
653 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
654 XAccessible parent
= null;
657 parent
= AccessibilityTools
.getAccessibleObjectForRole
658 (xRoot
, AccessibleRole
.HEADER
, "").getAccessibleChild(0);
659 oObj
= parent
.getAccessibleContext().getAccessibleChild(0);
660 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
661 fail(iabe
.getMessage());
665 System
.out
.println("ImplementationName " + utils
.getImplName(oObj
));
667 XAccessibleComponent accPC
=
668 UnoRuntime
.queryInterface(XAccessibleComponent
.class, parent
);
670 System
.out
.println("Parent-BoundsX= "+accPC
.getBounds().X
);
671 System
.out
.println("Parent-BoundsY= "+accPC
.getBounds().Y
);
672 System
.out
.println("Parent-BoundsWidth= "+accPC
.getBounds().Width
);
673 System
.out
.println("Parent-BoundsHeight= "+accPC
.getBounds().Height
);
675 XAccessibleComponent accPPC
=
676 UnoRuntime
.queryInterface(XAccessibleComponent
.class,
677 parent
.getAccessibleContext().getAccessibleParent());
679 System
.out
.println("P-Parent-BoundsX= "+accPPC
.getBounds().X
);
680 System
.out
.println("P-Parent-BoundsY= "+accPPC
.getBounds().Y
);
681 System
.out
.println("P-Parent-BoundsWidth= "+accPPC
.getBounds().Width
);
682 System
.out
.println("P-Parent-BoundsHeight= "+accPPC
.getBounds().Height
);
684 util
.utils
.pause(500);
686 System
.out
.println("Press any key when the header is not visible.");
688 byte[]b
= new byte[16];
690 } catch (Exception e
) {
696 parent
.getAccessibleContext().getAccessibleChildCount();
697 System
.out
.println("ChildCount: "+childCount
);
701 fail("Could access header although it was not visible on page.");
706 parent
= AccessibilityTools
.getAccessibleObjectForRole
707 (xRoot
, AccessibleRole
.FOOTER
, "").getAccessibleChild(0);
708 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
709 fail(iabe
.getMessage());
714 UnoRuntime
.queryInterface(XAccessibleComponent
.class, parent
);
716 System
.out
.println("Press any key when the footer is not visible.");
718 byte[]b
= new byte[16];
720 } catch (Exception e
) {
725 parent
.getAccessibleContext().getAccessibleChildCount();
726 System
.out
.println("ChildCount: "+childCount
);
730 fail("Could access footer although it was not visible on page.");
733 XComponent xComp
=UnoRuntime
.queryInterface(
734 XComponent
.class, xSpreadsheetDoc
);
743 * Check the preview of header cells
745 @Test public void checkPreviewHeaderCells() {
747 XInterface oObj
= null;
748 SOfficeFactory SOF
= SOfficeFactory
.getFactory( mXMSF
);
749 XSpreadsheetDocument xSpreadsheetDoc
= null;
752 System
.out
.println("Creating a spreadsheet document");
753 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
754 } catch (com
.sun
.star
.uno
.Exception e
) {
755 fail(e
.getMessage());
760 UnoRuntime
.queryInterface(XModel
.class, xSpreadsheetDoc
);
762 XController xController
= xModel
.getCurrentController();
764 //setting value of cell A1
767 System
.out
.println("Getting spreadsheet") ;
768 XSpreadsheets oSheets
= xSpreadsheetDoc
.getSheets() ;
769 XIndexAccess oIndexSheets
=
770 UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
771 Object o
= oIndexSheets
.getByIndex(0);
772 XSpreadsheet oSheet
= (XSpreadsheet
)AnyConverter
.toObject(
773 new com
.sun
.star
.uno
.Type(XSpreadsheet
.class), o
);
775 System
.out
.println("Getting a cell from sheet") ;
776 xCell
= oSheet
.getCellByPosition(0, 0);
777 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
778 fail(e
.getMessage());
779 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
780 fail(e
.getMessage());
782 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
783 fail(e
.getMessage());
787 xCell
.setFormula("Value");
789 //setting property 'PrintHeaders' of the style 'Default'
790 XStyleFamiliesSupplier xSFS
=
791 UnoRuntime
.queryInterface(XStyleFamiliesSupplier
.class,
793 XNameAccess xNA
= xSFS
.getStyleFamilies();
794 XPropertySet xPropSet
= null;
796 Object oPageStyles
= xNA
.getByName("PageStyles");
798 UnoRuntime
.queryInterface(XNameAccess
.class, oPageStyles
);
799 Object oDefStyle
= xNA
.getByName("Default");
801 UnoRuntime
.queryInterface(XPropertySet
.class, oDefStyle
);
802 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
803 fail(e
.getMessage());
805 } catch(com
.sun
.star
.container
.NoSuchElementException e
) {
806 fail(e
.getMessage());
811 xPropSet
.setPropertyValue("PrintHeaders", Boolean
.TRUE
);
812 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
813 fail(e
.getMessage());
815 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
816 fail(e
.getMessage());
818 } catch(com
.sun
.star
.beans
.PropertyVetoException e
) {
819 fail(e
.getMessage());
821 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
822 fail(e
.getMessage());
826 //switching to 'Print Preview' mode
828 XDispatchProvider xDispProv
=
829 UnoRuntime
.queryInterface(XDispatchProvider
.class, xController
);
830 XURLTransformer xParser
=
831 UnoRuntime
.queryInterface(XURLTransformer
.class,
832 mXMSF
.createInstance("com.sun.star.util.URLTransformer"));
833 URL
[] aParseURL
= new URL
[1];
834 aParseURL
[0] = new URL();
835 aParseURL
[0].Complete
= ".uno:PrintPreview";
836 xParser
.parseStrict(aParseURL
);
837 URL aURL
= aParseURL
[0];
838 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
839 if(xDispatcher
!= null)
841 xDispatcher
.dispatch( aURL
, null );
843 } catch (com
.sun
.star
.uno
.Exception e
) {
844 fail(e
.getMessage());
848 util
.utils
.pause(500);
850 XWindow xWindow
= AccessibilityTools
.getCurrentWindow(xModel
);
851 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
853 System
.out
.println("Press any key when the header cell is on top.");
855 byte[]b
= new byte[16];
857 } catch (Exception e
) {
863 System
.out
.println("Count: " +AccessibilityTools
.getAccessibleObjectForRole
864 (xRoot
, AccessibleRole
.TABLE
, "").getAccessibleChildCount());
865 System
.out
.println("Getting child 2");
866 oObj
= AccessibilityTools
.getAccessibleObjectForRole
867 (xRoot
, AccessibleRole
.TABLE
, "").getAccessibleChild(2);
868 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException iabe
) {
869 fail(iabe
.getMessage());
873 System
.out
.println("*** DEBUG INFO ***");
874 util
.dbg
.getSuppServices(oObj
);
875 System
.out
.println("****** IFC ******");
876 util
.dbg
.printInterfaces(oObj
);
877 System
.out
.println("*****************");
880 XAccessibleValue accV
=
881 UnoRuntime
.queryInterface(XAccessibleValue
.class, oObj
);
882 Object o
= accV
.getCurrentValue();
883 System
.out
.println("Getting the value: "+o
+ " is void " + util
.utils
.isVoid(o
));
886 XAccessibleComponent accC
=
887 UnoRuntime
.queryInterface(XAccessibleComponent
.class, oObj
);
889 System
.out
.println("BoundsX= "+accC
.getBounds().X
);
890 System
.out
.println("BoundsY= "+accC
.getBounds().Y
);
891 System
.out
.println("BoundsWidth= "+accC
.getBounds().Width
);
892 System
.out
.println("BoundsHeight= "+accC
.getBounds().Height
);
894 XComponent xComp
= UnoRuntime
.queryInterface(
895 XComponent
.class, xSpreadsheetDoc
);
905 * Check the preview of Shapes: load a document with shapes and see, if they
908 @Test public void checkPreviewShape() {
909 SOfficeFactory SOF
= SOfficeFactory
.getFactory( mXMSF
);
910 XSpreadsheetDocument xSpreadsheetDoc
= null;
911 XComponent xComp
= null;
912 XInterface oObj
= null;
915 String docName
= "calcshapes.sxc";
916 System
.out
.println("Loading a spreadsheetdocument.");
917 String url
= TestDocument
.getUrl(docName
);
918 System
.out
.println("loading document '" + url
+ "'");
919 xComp
= SOF
.loadDocument(url
);
920 assertNotNull(xComp
);
922 catch (com
.sun
.star
.uno
.Exception e
) {
923 fail(e
.getMessage());
927 util
.utils
.pause(500);
929 xSpreadsheetDoc
= UnoRuntime
.queryInterface(
930 XSpreadsheetDocument
.class, xComp
);
932 UnoRuntime
.queryInterface(XModel
.class, xSpreadsheetDoc
);
934 XController xController
= aModel
.getCurrentController();
936 // switching to 'Page Preview' mode
938 XDispatchProvider xDispProv
=
939 UnoRuntime
.queryInterface(XDispatchProvider
.class, xController
);
940 XURLTransformer xParser
=
941 UnoRuntime
.queryInterface(XURLTransformer
.class,
942 mXMSF
.createInstance("com.sun.star.util.URLTransformer"));
943 // Because it's an in/out parameter we must use an
944 // array of URL objects.
945 URL
[] aParseURL
= new URL
[1];
946 aParseURL
[0] = new URL();
947 aParseURL
[0].Complete
= ".uno:PrintPreview";
948 xParser
.parseStrict(aParseURL
);
949 URL aURL
= aParseURL
[0];
950 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
951 if(xDispatcher
!= null)
953 xDispatcher
.dispatch( aURL
, null );
955 } catch (com
.sun
.star
.uno
.Exception e
) {
956 fail("Couldn't change mode");
960 util
.utils
.pause(500);
962 System
.out
.println("Press any key when a shape is on top.");
964 byte[]b
= new byte[16];
966 } catch (Exception e
) {
970 XWindow xWindow
= AccessibilityTools
.getCurrentWindow(aModel
);
971 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
974 XAccessibleContext con
= AccessibilityTools
.getAccessibleObjectForRole
975 (xRoot
, AccessibleRole
.SHAPE
, "");
976 System
.out
.println("Name of AccessibleContext: " + con
.getAccessibleName());
978 } catch (Exception e
) {
979 fail(e
.getMessage());
983 System
.out
.println("ImplementationName: " + utils
.getImplName(oObj
));
984 util
.dbg
.printInterfaces(oObj
);
989 @BeforeClass public static void setUpConnection() throws Exception
{
993 @AfterClass public static void tearDownConnection()
994 throws InterruptedException
, com
.sun
.star
.uno
.Exception
996 connection
.tearDown();
999 private static final OfficeConnection connection
= new OfficeConnection();