tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / qa / complex / calcPreview / ViewForwarder.java
blobd1490013a9fa8ccaa9044ed84ef769a600750976
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 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;
45 import util.utils;
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.*;
63 /**
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;
72 /**
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;
88 try {
89 System.out.println("Creating a spreadsheet document");
90 xSpreadsheetDoc = SOF.createCalcDoc(null);
91 } catch (com.sun.star.uno.Exception e) {
92 fail(e.getMessage());
93 return;
96 XInterface oObj = null;
98 // inserting some content to have non-empty page preview
99 XCell xCell = null;
100 try {
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 creating relation :");
116 fail(e.getMessage());
117 } catch(com.sun.star.lang.WrappedTargetException e) {
118 System.out.println("Exception creating relation :");
119 fail(e.getMessage());
120 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
121 System.out.println("Exception creating relation :");
122 fail(e.getMessage());
125 XModel aModel =
126 UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc);
128 XController xController = aModel.getCurrentController();
130 // get page styles
131 XStyleFamiliesSupplier StyleFam =
132 UnoRuntime.queryInterface(
133 XStyleFamiliesSupplier.class,
134 xSpreadsheetDoc );
135 XNameAccess StyleFamNames = StyleFam.getStyleFamilies();
136 XStyle StdStyle = null;
138 try{
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());
150 return;
151 } catch(com.sun.star.container.NoSuchElementException e){
152 fail(e.getMessage());
153 return;
156 //get the property-set
157 final XPropertySet PropSet =
158 UnoRuntime.queryInterface(XPropertySet.class, StdStyle);
160 XHeaderFooterContent RPHFC = null;
162 // get the header
163 try {
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());
172 return;
173 } catch(com.sun.star.beans.UnknownPropertyException e){
174 fail(e.getMessage());
175 return;
178 // insert text into header
179 XText center = RPHFC.getCenterText();
180 center.setString("First line \n\r Second line \n\r third line ");
181 try {
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) {}
188 // get footer
189 RPHFC = null;
190 try {
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());
198 return;
199 } catch(com.sun.star.beans.UnknownPropertyException e){
200 fail(e.getMessage());
201 return;
204 // insert text into footer
205 center = RPHFC.getCenterText();
206 center.setString("Third last line\n\r Second last line\n\r last line");
207 try {
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
215 try {
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");
235 return;
238 util.utils.waitForEventIdle(mXMSF);
240 System.out.println("Press any key after resizing ");
241 try{
242 byte[]b = new byte[16];
243 System.in.read(b);
244 } catch (Exception e) {
245 e.printStackTrace();
248 XWindow xWindow = AccessibilityTools.getCurrentWindow(aModel);
249 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
250 XAccessible parent = null;
252 try {
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());
258 return;
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.waitForEventIdle(mXMSF);
282 System.out.println("Press any key when the second line is on top");
283 try{
284 byte[]b = new byte[16];
285 System.in.read(b);
286 } catch (Exception e) {
287 e.printStackTrace();
290 try {
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());
297 return;
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);
311 accPC =
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);
319 accPPC =
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.");
331 try{
332 byte[]b = new byte[16];
333 System.in.read(b);
334 } catch (Exception e) {
335 e.printStackTrace();
338 try {
339 parent = AccessibilityTools.getAccessibleObjectForRole
340 (xRoot, AccessibleRole.FOOTER, "").getAccessibleChild(0);
341 } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
342 fail(iabe.getMessage());
343 return;
346 accPC =
347 UnoRuntime.queryInterface(XAccessibleComponent.class, parent);
349 try {
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());
356 return;
359 accT =
360 UnoRuntime.queryInterface(XAccessibleText.class, oObj);
361 System.out.println("Getting the text: "+accT.getText());
363 accC =
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);
370 accPC =
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);
378 accPPC =
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");
389 try{
390 byte[]b = new byte[16];
391 System.in.read(b);
392 } catch (Exception e) {
393 e.printStackTrace();
396 try {
397 parent = AccessibilityTools.getAccessibleObjectForRole
398 (xRoot, AccessibleRole.DOCUMENT, "").getAccessibleChild(0);
399 } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
400 fail(iabe.getMessage());
401 return;
403 System.out.println("PARENT: " + parent.getAccessibleContext().getAccessibleName());
404 accPC =
405 UnoRuntime.queryInterface(XAccessibleComponent.class, parent);
407 long cCount = 0;
408 try {
409 cCount =
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());
416 return;
419 for (long i=0; i<cCount; i++) {
420 try {
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());
425 return;
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);
439 else
441 System.out.println("Name of Object: " + o.getClass().getName());
443 System.out.println("Getting the value: "+accV.getCurrentValue());
448 accC =
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);
455 accPC =
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);
463 accPPC =
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);
474 xComp.dispose();
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;
492 try {
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());
497 return;
500 XInterface oObj = null;
502 // inserting some content to have non-empty page preview
503 XCell xCell = null;
504 try {
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 creating relation :");
520 fail(e.getMessage());
521 } catch(com.sun.star.lang.WrappedTargetException e) {
522 System.out.println("Exception creating relation :");
523 fail(e.getMessage());
524 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
525 System.out.println("Exception creating relation :");
526 fail(e.getMessage());
529 XModel aModel =
530 UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc);
532 XController xController = aModel.getCurrentController();
534 // get page styles
535 XStyleFamiliesSupplier StyleFam =
536 UnoRuntime.queryInterface(
537 XStyleFamiliesSupplier.class,
538 xSpreadsheetDoc );
539 XNameAccess StyleFamNames = StyleFam.getStyleFamilies();
540 XStyle StdStyle = null;
542 try{
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());
554 return;
555 } catch(com.sun.star.container.NoSuchElementException e){
556 fail(e.getMessage());
557 return;
560 //get the property-set
561 final XPropertySet PropSet =
562 UnoRuntime.queryInterface(XPropertySet.class, StdStyle);
564 XHeaderFooterContent RPHFC = null;
566 // get the header
567 System.out.println( "Creating a test environment" );
568 try {
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());
576 return;
577 } catch(com.sun.star.beans.UnknownPropertyException e){
578 fail(e.getMessage());
579 return;
582 // insert text into header
583 XText center = RPHFC.getCenterText();
584 center.setString("First line \n\r Second line \n\r third line ");
585 try {
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) {}
592 // get footer
593 RPHFC = null;
594 try {
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());
602 return;
603 } catch(com.sun.star.beans.UnknownPropertyException e){
604 fail(e.getMessage());
605 return;
608 // insert text into footer
609 center = RPHFC.getCenterText();
610 center.setString("Third last line\n\r Second last line\n\r last line");
611 try {
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
619 try {
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");
639 return;
642 util.utils.waitForEventIdle(mXMSF);
644 System.out.println("Press any key after resizing ");
645 try{
646 byte[]b = new byte[16];
647 System.in.read(b);
648 } catch (Exception e) {
649 e.printStackTrace();
652 XWindow xWindow = AccessibilityTools.getCurrentWindow(aModel);
653 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
654 XAccessible parent = null;
656 try {
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());
662 return;
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.waitForEventIdle(mXMSF);
686 System.out.println("Press any key when the header is not visible.");
687 try{
688 byte[]b = new byte[16];
689 System.in.read(b);
690 } catch (Exception e) {
691 e.printStackTrace();
694 long childCount = 0;
695 childCount =
696 parent.getAccessibleContext().getAccessibleChildCount();
697 System.out.println("ChildCount: "+childCount);
699 if (childCount != 0)
701 fail("Could access header although it was not visible on page.");
705 try {
706 parent = AccessibilityTools.getAccessibleObjectForRole
707 (xRoot, AccessibleRole.FOOTER, "").getAccessibleChild(0);
708 } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
709 fail(iabe.getMessage());
710 return;
713 accPC =
714 UnoRuntime.queryInterface(XAccessibleComponent.class, parent);
716 System.out.println("Press any key when the footer is not visible.");
717 try{
718 byte[]b = new byte[16];
719 System.in.read(b);
720 } catch (Exception e) {
721 e.printStackTrace();
724 childCount =
725 parent.getAccessibleContext().getAccessibleChildCount();
726 System.out.println("ChildCount: "+childCount);
728 if (childCount != 0)
730 fail("Could access footer although it was not visible on page.");
733 XComponent xComp =UnoRuntime.queryInterface(
734 XComponent.class, xSpreadsheetDoc);
735 xComp.dispose();
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;
751 try {
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());
756 return;
759 XModel xModel =
760 UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc);
762 XController xController = xModel.getCurrentController();
764 //setting value of cell A1
765 XCell xCell = null;
766 try {
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());
781 return;
782 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
783 fail(e.getMessage());
784 return;
787 xCell.setFormula("Value");
789 //setting property 'PrintHeaders' of the style 'Default'
790 XStyleFamiliesSupplier xSFS =
791 UnoRuntime.queryInterface(XStyleFamiliesSupplier.class,
792 xSpreadsheetDoc);
793 XNameAccess xNA = xSFS.getStyleFamilies();
794 XPropertySet xPropSet = null;
795 try {
796 Object oPageStyles = xNA.getByName("PageStyles");
797 xNA =
798 UnoRuntime.queryInterface(XNameAccess.class, oPageStyles);
799 Object oDefStyle = xNA.getByName("Default");
800 xPropSet =
801 UnoRuntime.queryInterface(XPropertySet.class, oDefStyle);
802 } catch(com.sun.star.lang.WrappedTargetException e) {
803 fail(e.getMessage());
804 return;
805 } catch(com.sun.star.container.NoSuchElementException e) {
806 fail(e.getMessage());
807 return;
810 try {
811 xPropSet.setPropertyValue("PrintHeaders", Boolean.TRUE);
812 } catch(com.sun.star.lang.WrappedTargetException e) {
813 fail(e.getMessage());
814 return;
815 } catch(com.sun.star.lang.IllegalArgumentException e) {
816 fail(e.getMessage());
817 return;
818 } catch(com.sun.star.beans.PropertyVetoException e) {
819 fail(e.getMessage());
820 return;
821 } catch(com.sun.star.beans.UnknownPropertyException e) {
822 fail(e.getMessage());
823 return;
826 //switching to 'Print Preview' mode
827 try {
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());
845 return;
848 util.utils.waitForEventIdle(mXMSF);
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.");
854 try{
855 byte[]b = new byte[16];
856 System.in.read(b);
857 } catch (Exception e) {
858 e.printStackTrace();
862 try {
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());
870 return;
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);
896 xComp.dispose();
905 * Check the preview of Shapes: load a document with shapes and see, if they
906 * are accessible.
908 @Test public void checkPreviewShape() {
909 SOfficeFactory SOF = SOfficeFactory.getFactory( mXMSF );
910 XSpreadsheetDocument xSpreadsheetDoc = null;
911 XComponent xComp = null;
912 XInterface oObj = null;
914 try {
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());
924 return;
927 util.utils.waitForEventIdle(mXMSF);
929 xSpreadsheetDoc = UnoRuntime.queryInterface(
930 XSpreadsheetDocument.class, xComp);
931 XModel aModel =
932 UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc);
934 XController xController = aModel.getCurrentController();
936 // switching to 'Page Preview' mode
937 try {
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");
957 return;
960 util.utils.waitForEventIdle(mXMSF);
962 System.out.println("Press any key when a shape is on top.");
963 try{
964 byte[]b = new byte[16];
965 System.in.read(b);
966 } catch (Exception e) {
967 e.printStackTrace();
970 XWindow xWindow = AccessibilityTools.getCurrentWindow(aModel);
971 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
973 try {
974 XAccessibleContext con = AccessibilityTools.getAccessibleObjectForRole
975 (xRoot, AccessibleRole.SHAPE, "");
976 System.out.println("Name of AccessibleContext: " + con.getAccessibleName());
977 oObj = con;
978 } catch (Exception e) {
979 fail(e.getMessage());
980 return;
983 System.out.println("ImplementationName: " + utils.getImplName(oObj));
984 util.dbg.printInterfaces(oObj);
986 xComp.dispose();
989 @BeforeClass public static void setUpConnection() throws Exception {
990 connection.setUp();
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();