fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sc / qa / complex / calcPreview / ViewForwarder.java
blob192bffb1421417e7da569d9a4dff61b89b8a8be9
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 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;
50 import util.utils;
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.*;
80 /**
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"
97 // };
98 // }
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;
121 try {
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());
126 return;
129 XInterface oObj = null;
131 // inserting some content to have non-empty page preview
132 XCell xCell = null;
133 try {
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());
158 XModel aModel =
159 UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc);
161 XController xController = aModel.getCurrentController();
163 // get page styles
164 XStyleFamiliesSupplier StyleFam =
165 UnoRuntime.queryInterface(
166 XStyleFamiliesSupplier.class,
167 xSpreadsheetDoc );
168 XNameAccess StyleFamNames = StyleFam.getStyleFamilies();
169 XStyle StdStyle = null;
171 try{
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());
183 return;
184 } catch(com.sun.star.container.NoSuchElementException e){
185 fail(e.getMessage());
186 return;
189 //get the property-set
190 final XPropertySet PropSet =
191 UnoRuntime.queryInterface(XPropertySet.class, StdStyle);
193 XHeaderFooterContent RPHFC = null;
195 // get the header
196 try {
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());
205 return;
206 } catch(com.sun.star.beans.UnknownPropertyException e){
207 fail(e.getMessage());
208 return;
211 // insert text into header
212 XText center = RPHFC.getCenterText();
213 center.setString("First line \n\r Second line \n\r third line ");
214 try {
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) {}
221 // get footer
222 RPHFC = null;
223 try {
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());
231 return;
232 } catch(com.sun.star.beans.UnknownPropertyException e){
233 fail(e.getMessage());
234 return;
237 // insert text into footer
238 center = RPHFC.getCenterText();
239 center.setString("Third last line\n\r Second last line\n\r last line");
240 try {
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
248 try {
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");
268 return;
271 try {
272 Thread.sleep(500);
273 } catch (InterruptedException ex) {}
275 System.out.println("Press any key after resizing ");
276 try{
277 byte[]b = new byte[16];
278 System.in.read(b);
279 } catch (Exception e) {
280 e.printStackTrace();
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;
290 try {
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());
296 return;
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);
318 try {
319 Thread.sleep(500);
320 } catch (InterruptedException ex) {}
322 System.out.println("Press any key when the second line is on top");
323 try{
324 byte[]b = new byte[16];
325 System.in.read(b);
326 } catch (Exception e) {
327 e.printStackTrace();
330 try {
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());
337 return;
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);
351 accPC =
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);
359 accPPC =
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.");
371 try{
372 byte[]b = new byte[16];
373 System.in.read(b);
374 } catch (Exception e) {
375 e.printStackTrace();
378 try {
379 parent = AccessibilityTools.getAccessibleObjectForRole
380 (xRoot, AccessibleRole.FOOTER, "").getAccessibleChild(0);
381 } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
382 fail(iabe.getMessage());
383 return;
386 accPC =
387 UnoRuntime.queryInterface(XAccessibleComponent.class, parent);
389 try {
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());
396 return;
399 accT =
400 UnoRuntime.queryInterface(XAccessibleText.class, oObj);
401 System.out.println("Getting the text: "+accT.getText());
403 accC =
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);
410 accPC =
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);
418 accPPC =
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");
429 try{
430 byte[]b = new byte[16];
431 System.in.read(b);
432 } catch (Exception e) {
433 e.printStackTrace();
436 try {
437 parent = AccessibilityTools.getAccessibleObjectForRole
438 (xRoot, AccessibleRole.DOCUMENT, "").getAccessibleChild(0);
439 } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
440 fail(iabe.getMessage());
441 return;
443 System.out.println("PARENT: " + parent.getAccessibleContext().getAccessibleName());
444 accPC =
445 UnoRuntime.queryInterface(XAccessibleComponent.class, parent);
447 int cCount = 0;
448 try {
449 cCount =
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());
456 return;
459 for (int i=0; i<cCount; i++) {
460 try {
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());
465 return;
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);
479 else
481 System.out.println("Name of Object: " + o.getClass().getName());
483 System.out.println("Getting the value: "+accV.getCurrentValue());
488 accC =
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);
495 accPC =
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);
503 accPPC =
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);
514 xComp.dispose();
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;
532 try {
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());
537 return;
540 XInterface oObj = null;
542 // inserting some content to have non-empty page preview
543 XCell xCell = null;
544 try {
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());
569 XModel aModel =
570 UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc);
572 XController xController = aModel.getCurrentController();
574 // get page styles
575 XStyleFamiliesSupplier StyleFam =
576 UnoRuntime.queryInterface(
577 XStyleFamiliesSupplier.class,
578 xSpreadsheetDoc );
579 XNameAccess StyleFamNames = StyleFam.getStyleFamilies();
580 XStyle StdStyle = null;
582 try{
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());
594 return;
595 } catch(com.sun.star.container.NoSuchElementException e){
596 fail(e.getMessage());
597 return;
600 //get the property-set
601 final XPropertySet PropSet =
602 UnoRuntime.queryInterface(XPropertySet.class, StdStyle);
604 XHeaderFooterContent RPHFC = null;
606 // get the header
607 System.out.println( "Creating a test environment" );
608 try {
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());
616 return;
617 } catch(com.sun.star.beans.UnknownPropertyException e){
618 fail(e.getMessage());
619 return;
622 // insert text into header
623 XText center = RPHFC.getCenterText();
624 center.setString("First line \n\r Second line \n\r third line ");
625 try {
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) {}
632 // get footer
633 RPHFC = null;
634 try {
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());
642 return;
643 } catch(com.sun.star.beans.UnknownPropertyException e){
644 fail(e.getMessage());
645 return;
648 // insert text into footer
649 center = RPHFC.getCenterText();
650 center.setString("Third last line\n\r Second last line\n\r last line");
651 try {
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
659 try {
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");
679 return;
682 try {
683 Thread.sleep(500);
684 } catch (InterruptedException ex) {}
686 System.out.println("Press any key after resizing ");
687 try{
688 byte[]b = new byte[16];
689 System.in.read(b);
690 } catch (Exception e) {
691 e.printStackTrace();
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;
701 try {
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());
707 return;
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);
729 try {
730 Thread.sleep(500);
731 } catch (InterruptedException ex) {}
733 System.out.println("Press any key when the header is not visible.");
734 try{
735 byte[]b = new byte[16];
736 System.in.read(b);
737 } catch (Exception e) {
738 e.printStackTrace();
741 int childCount = 0;
742 childCount =
743 parent.getAccessibleContext().getAccessibleChildCount();
744 System.out.println("ChildCount: "+childCount);
746 if (childCount != 0)
748 fail("Could access header although it was not visible on page.");
752 try {
753 parent = AccessibilityTools.getAccessibleObjectForRole
754 (xRoot, AccessibleRole.FOOTER, "").getAccessibleChild(0);
755 } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
756 fail(iabe.getMessage());
757 return;
760 accPC =
761 UnoRuntime.queryInterface(XAccessibleComponent.class, parent);
763 System.out.println("Press any key when the footer is not visible.");
764 try{
765 byte[]b = new byte[16];
766 System.in.read(b);
767 } catch (Exception e) {
768 e.printStackTrace();
771 childCount =
772 parent.getAccessibleContext().getAccessibleChildCount();
773 System.out.println("ChildCount: "+childCount);
775 if (childCount != 0)
777 fail("Could access footer although it was not visible on page.");
780 XComponent xComp =UnoRuntime.queryInterface(
781 XComponent.class, xSpreadsheetDoc);
782 xComp.dispose();
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;
798 try {
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());
803 return;
806 XModel xModel =
807 UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc);
809 XController xController = xModel.getCurrentController();
811 //setting value of cell A1
812 XCell xCell = null;
813 try {
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());
828 return;
829 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
830 fail(e.getMessage());
831 return;
834 xCell.setFormula("Value");
836 //setting property 'PrintHeaders' of the style 'Default'
837 XStyleFamiliesSupplier xSFS =
838 UnoRuntime.queryInterface(XStyleFamiliesSupplier.class,
839 xSpreadsheetDoc);
840 XNameAccess xNA = xSFS.getStyleFamilies();
841 XPropertySet xPropSet = null;
842 try {
843 Object oPageStyles = xNA.getByName("PageStyles");
844 xNA =
845 UnoRuntime.queryInterface(XNameAccess.class, oPageStyles);
846 Object oDefStyle = xNA.getByName("Default");
847 xPropSet =
848 UnoRuntime.queryInterface(XPropertySet.class, oDefStyle);
849 } catch(com.sun.star.lang.WrappedTargetException e) {
850 fail(e.getMessage());
851 return;
852 } catch(com.sun.star.container.NoSuchElementException e) {
853 fail(e.getMessage());
854 return;
857 try {
858 xPropSet.setPropertyValue("PrintHeaders", new Boolean(true));
859 } catch(com.sun.star.lang.WrappedTargetException e) {
860 fail(e.getMessage());
861 return;
862 } catch(com.sun.star.lang.IllegalArgumentException e) {
863 fail(e.getMessage());
864 return;
865 } catch(com.sun.star.beans.PropertyVetoException e) {
866 fail(e.getMessage());
867 return;
868 } catch(com.sun.star.beans.UnknownPropertyException e) {
869 fail(e.getMessage());
870 return;
873 //switching to 'Print Preview' mode
874 try {
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());
892 return;
895 try {
896 Thread.sleep(500) ;
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.");
909 try{
910 byte[]b = new byte[16];
911 System.in.read(b);
912 } catch (Exception e) {
913 e.printStackTrace();
917 XAccessible parent = null;
919 try {
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());
930 return;
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);
942 try {
943 System.out.println("Children now: " + accCtx.getAccessibleChild(0).getAccessibleContext().getAccessibleChildCount());
944 } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
945 fail(iabe.getMessage());
946 return;
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);
966 xComp.dispose();
975 * Check the preview of Shapes: load a document with shapes and see, if they
976 * are accessible.
978 @Test public void checkPreviewShape() {
979 SOfficeFactory SOF = SOfficeFactory.getFactory( mXMSF );
980 XSpreadsheetDocument xSpreadsheetDoc = null;
981 XComponent xComp = null;
982 XInterface oObj = null;
984 try {
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());
995 return;
998 try {
999 Thread.sleep(500) ;
1000 } catch (InterruptedException e) {
1001 System.out.println("While waiting :" + e) ;
1004 if (xComp == null) {
1005 fail("loading document failed.");
1006 return;
1009 xSpreadsheetDoc = UnoRuntime.queryInterface(
1010 XSpreadsheetDocument.class, xComp);
1011 XModel aModel =
1012 UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc);
1014 XController xController = aModel.getCurrentController();
1016 // switching to 'Page Preview' mode
1017 try {
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");
1037 return;
1040 try {
1041 Thread.sleep(500) ;
1042 } catch (InterruptedException e) {
1043 System.out.println("While waiting :" + e) ;
1048 System.out.println("Press any key when a shape is on top.");
1049 try{
1050 byte[]b = new byte[16];
1051 System.in.read(b);
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;
1063 try {
1064 XAccessibleContext con = AccessibilityTools.getAccessibleObjectForRole
1065 (xRoot, AccessibleRole.SHAPE, "");
1066 System.out.println("Name of AccessibleContext: " + con.getAccessibleName());
1067 oObj = con;
1068 } catch (Exception e) {
1069 fail(e.getMessage());
1070 return;
1073 System.out.println("ImplementationName: " + utils.getImplName(oObj));
1074 util.dbg.printInterfaces(oObj);
1076 xComp.dispose();
1079 @BeforeClass public static void setUpConnection() throws Exception {
1080 connection.setUp();
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();