1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package complex.calcPreview;
25 
26 // import complexlib.ComplexTestCase;
27 
28 import com.sun.star.awt.XWindow;
29 import com.sun.star.container.XIndexAccess;
30 import com.sun.star.frame.XController;
31 import com.sun.star.frame.XDispatch;
32 import com.sun.star.frame.XDispatchProvider;
33 import com.sun.star.frame.XModel;
34 // import com.sun.star.lang.XComponent;
35 import com.sun.star.lang.XMultiServiceFactory;
36 import com.sun.star.sheet.XSpreadsheet;
37 // import com.sun.star.sheet.XSpreadsheetDocument;
38 import com.sun.star.sheet.XSpreadsheets;
39 import com.sun.star.table.XCell;
40 // import com.sun.star.uno.Any;
41 import com.sun.star.uno.AnyConverter;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XInterface;
44 import com.sun.star.util.URL;
45 import com.sun.star.util.XURLTransformer;
46 import com.sun.star.accessibility.AccessibleRole;
47 import com.sun.star.accessibility.XAccessible;
48 import com.sun.star.accessibility.XAccessibleText;
49 import com.sun.star.accessibility.XAccessibleValue;
50 import com.sun.star.accessibility.XAccessibleComponent;
51 import com.sun.star.accessibility.XAccessibleContext;
52 
53 import util.AccessibilityTools;
54 import util.SOfficeFactory;
55 import util.utils;
56 
57 import com.sun.star.beans.XPropertySet;
58 // import com.sun.star.beans.XPropertySetInfo;
59 import com.sun.star.container.XNameAccess;
60 import com.sun.star.lang.XComponent;
61 import com.sun.star.sheet.XHeaderFooterContent;
62 import com.sun.star.sheet.XSpreadsheetDocument;
63 import com.sun.star.style.XStyle;
64 import com.sun.star.style.XStyleFamiliesSupplier;
65 import com.sun.star.text.XText;
66 // import com.sun.star.drawing.XDrawPageSupplier;
67 // import com.sun.star.drawing.XDrawPage;
68 // import com.sun.star.drawing.XShape;
69 // import com.sun.star.drawing.XShapes;
70 
71 
72 // import com.sun.star.beans.Property;
73 // import com.sun.star.lang.XServiceInfo;
74 
75 
76 
77 // import org.junit.After;
78 import org.junit.AfterClass;
79 import org.junit.Before;
80 import org.junit.BeforeClass;
81 import org.junit.Test;
82 import org.openoffice.test.OfficeConnection;
83 import static org.junit.Assert.*;
84 
85 /**
86  * A complex test for the preview of Calc documents. This complex test
87  * needs interaction from the user: documents have to be resized and moved.
88  */
89 public class ViewForwarder {
90 
91     /** The MultiServiceFactory **/
92     private XMultiServiceFactory mXMSF = null;
93 
94     /** Get all test methods.
95      * @return The test methods.
96      */
97 //    public String[] getTestMethodNames() {
98 //        return new String[]{"checkPositiveViewForwarder",
99 //                            "checkNegativeViewForwarder",
100 //                            "checkPreviewHeaderCells",
101 //                            "checkPreviewShape"
102 //                            };
103 //    }
104 
105     /**
106      * Get a MultiServiceFactory from the Office before the test.
107      */
108     @Before public void before()
109     {
110         mXMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
111         // SOfficeFactory SOF = SOfficeFactory.getFactory(mXMSF);
112 
113         // param = new TestParameters();
114         // param.put("ServiceFactory", xMsf);
115         // mXMSF = (XMultiServiceFactory)param.getMSF();
116     }
117 
118 
119     /** Create a spreadsheet document, insert some text, header and footer.
120      * Let the user resize the document and check the contents.
121      */
122     @Test public void checkPositiveViewForwarder() {
123         SOfficeFactory SOF = SOfficeFactory.getFactory( mXMSF );
124         XSpreadsheetDocument xSpreadsheetDoc = null;
125 
126         try {
127             System.out.println("Creating a spreadsheet document");
128             xSpreadsheetDoc = SOF.createCalcDoc(null);
129         } catch (com.sun.star.uno.Exception e) {
130             fail(e.getMessage());
131             return;
132         }
133 
134         XInterface oObj = null;
135 
136         // inserting some content to have non-empty page preview
137         XCell xCell = null;
138         try {
139             XSpreadsheets oSheets = xSpreadsheetDoc.getSheets() ;
140             XIndexAccess oIndexSheets =
141                 UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
142             Object o = oIndexSheets.getByIndex(0);
143             XSpreadsheet oSheet = (XSpreadsheet)AnyConverter.toObject(
144                             new com.sun.star.uno.Type(XSpreadsheet.class), o);
145             xCell = oSheet.getCellByPosition(0, 0) ;
146             xCell.setFormula("ScAccessiblePageHeader");
147 
148             xCell = oSheet.getCellByPosition(0, 1) ;
149             xCell.setFormula("Cell 1");
150             xCell = oSheet.getCellByPosition(0, 2) ;
151             xCell.setFormula("Cell 2");
152         } catch(com.sun.star.lang.IllegalArgumentException e) {
153             System.out.println("Exception ceating relation :");
154             fail(e.getMessage());
155         } catch(com.sun.star.lang.WrappedTargetException e) {
156             System.out.println("Exception ceating relation :");
157             fail(e.getMessage());
158         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
159             System.out.println("Exception ceating relation :");
160             fail(e.getMessage());
161         }
162 
163         XModel aModel =
164             UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc);
165 
166         XController xController = aModel.getCurrentController();
167 
168         // get page styles
169         XStyleFamiliesSupplier StyleFam =
170             UnoRuntime.queryInterface(
171                 XStyleFamiliesSupplier.class,
172                 xSpreadsheetDoc );
173         XNameAccess StyleFamNames = StyleFam.getStyleFamilies();
174         XStyle StdStyle = null;
175 
176         try{
177             Object o = StyleFamNames.getByName("PageStyles");
178             XNameAccess PageStyles = (XNameAccess)AnyConverter.toObject(
179                             new com.sun.star.uno.Type(XNameAccess.class), o);
180 
181             o = PageStyles.getByName("Default");
182             StdStyle = (XStyle)AnyConverter.toObject(
183                             new com.sun.star.uno.Type(XStyle.class), o);
184         } catch(com.sun.star.lang.IllegalArgumentException e) {
185             fail(e.getMessage());
186         } catch(com.sun.star.lang.WrappedTargetException e){
187             fail(e.getMessage());
188             return;
189         } catch(com.sun.star.container.NoSuchElementException e){
190             fail(e.getMessage());
191             return;
192         }
193 
194         //get the property-set
195         final XPropertySet PropSet =
196             UnoRuntime.queryInterface(XPropertySet.class, StdStyle);
197 
198         XHeaderFooterContent RPHFC = null;
199 
200         // get the header
201         try {
202             Object o = PropSet.getPropertyValue("RightPageHeaderContent");
203             RPHFC = (XHeaderFooterContent)AnyConverter.toObject(
204                     new com.sun.star.uno.Type(XHeaderFooterContent.class), o);
205 
206         } catch(com.sun.star.lang.IllegalArgumentException e) {
207             fail(e.getMessage());
208         } catch(com.sun.star.lang.WrappedTargetException e){
209             fail(e.getMessage());
210             return;
211         } catch(com.sun.star.beans.UnknownPropertyException e){
212             fail(e.getMessage());
213             return;
214         }
215 
216         // insert text into header
217         XText center = RPHFC.getCenterText();
218         center.setString("First line \n\r Second line \n\r third line ");
219         try {
220             PropSet.setPropertyValue("RightPageHeaderContent",RPHFC);
221         } catch (com.sun.star.beans.UnknownPropertyException e) {
222         } catch (com.sun.star.beans.PropertyVetoException e) {
223         } catch (com.sun.star.lang.IllegalArgumentException e) {
224         } catch (com.sun.star.lang.WrappedTargetException e) {}
225 
226         // get footer
227         RPHFC = null;
228         try {
229             Object o = PropSet.getPropertyValue("RightPageHeaderContent");
230             RPHFC = (XHeaderFooterContent)AnyConverter.toObject(
231                     new com.sun.star.uno.Type(XHeaderFooterContent.class), o);
232         } catch(com.sun.star.lang.IllegalArgumentException e) {
233             fail(e.getMessage());
234         } catch(com.sun.star.lang.WrappedTargetException e){
235             fail(e.getMessage());
236             return;
237         } catch(com.sun.star.beans.UnknownPropertyException e){
238             fail(e.getMessage());
239             return;
240         }
241 
242         // insert text into footer
243         center = RPHFC.getCenterText();
244         center.setString("Third last line\n\r Second last line\n\r last line");
245         try {
246             PropSet.setPropertyValue("RightPageFooterContent",RPHFC);
247         } catch (com.sun.star.beans.UnknownPropertyException e) {
248         } catch (com.sun.star.beans.PropertyVetoException e) {
249         } catch (com.sun.star.lang.IllegalArgumentException e) {
250         } catch (com.sun.star.lang.WrappedTargetException e) {}
251 
252         // switching to 'Page Preview' mode
253         try {
254             XDispatchProvider xDispProv =
255                 UnoRuntime.queryInterface(XDispatchProvider.class, xController);
256             XURLTransformer xParser =
257                 UnoRuntime.queryInterface(XURLTransformer.class,
258             mXMSF.createInstance("com.sun.star.util.URLTransformer"));
259             // Because it's an in/out parameter we must use an
260             // array of URL objects.
261             URL[] aParseURL = new URL[1];
262             aParseURL[0] = new URL();
263             aParseURL[0].Complete = ".uno:PrintPreview";
264             xParser.parseStrict(aParseURL);
265             URL aURL = aParseURL[0];
266             XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0);
267             if(xDispatcher != null)
268             {
269                 xDispatcher.dispatch( aURL, null );
270             }
271         } catch (com.sun.star.uno.Exception e) {
272             fail("Couldn't change mode");
273             return;
274         }
275 
276         try {
277             Thread.sleep(500);
278         } catch (InterruptedException ex) {}
279 
280         System.out.println("Press any key after resizing ");
281         try{
282             byte[]b = new byte[16];
283             System.in.read(b);
284         } catch (Exception e) {
285             e.printStackTrace();
286         }
287 
288         // get the accessible content
289         AccessibilityTools at = new AccessibilityTools();
290 
291         XWindow xWindow = at.getCurrentWindow(mXMSF, aModel);
292         XAccessible xRoot = at.getAccessibleObject(xWindow);
293         XAccessible parent = null;
294 
295         try {
296             parent = at.getAccessibleObjectForRole
297                 (xRoot, AccessibleRole.HEADER, "").getAccessibleChild(0);
298             oObj = parent.getAccessibleContext().getAccessibleChild(0);
299         } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
300             fail(iabe.getMessage());
301             return;
302         }
303 
304         System.out.println("ImplementationName " + utils.getImplName(oObj));
305 
306         XAccessibleComponent accPC =
307                 UnoRuntime.queryInterface(XAccessibleComponent.class, parent);
308 
309         System.out.println("Parent-BoundsX= "+accPC.getBounds().X);
310         System.out.println("Parent-BoundsY= "+accPC.getBounds().Y);
311         System.out.println("Parent-BoundsWidth= "+accPC.getBounds().Width);
312         System.out.println("Parent-BoundsHeight= "+accPC.getBounds().Height);
313 
314         XAccessibleComponent accPPC =
315                         UnoRuntime.queryInterface(XAccessibleComponent.class,
316                         parent.getAccessibleContext().getAccessibleParent());
317 
318         System.out.println("P-Parent-BoundsX= "+accPPC.getBounds().X);
319         System.out.println("P-Parent-BoundsY= "+accPPC.getBounds().Y);
320         System.out.println("P-Parent-BoundsWidth= "+accPPC.getBounds().Width);
321         System.out.println("P-Parent-BoundsHeight= "+accPPC.getBounds().Height);
322 
323         try {
324             Thread.sleep(500);
325         } catch (InterruptedException ex) {}
326 
327         System.out.println("Press any key when the second line is on top");
328         try{
329             byte[]b = new byte[16];
330             System.in.read(b);
331         } catch (Exception e) {
332             e.printStackTrace();
333         }
334 
335         try {
336             System.out.println("ChildCount: "+
337                     parent.getAccessibleContext().getAccessibleChildCount());
338             System.out.println("Getting child 0 again");
339             oObj = parent.getAccessibleContext().getAccessibleChild(0);
340         } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
341             fail(iabe.getMessage());
342             return;
343         }
344 
345         XAccessibleText accT =
346                 UnoRuntime.queryInterface(XAccessibleText.class, oObj);
347         System.out.println("Getting the text: "+accT.getText());
348 
349         XAccessibleComponent accC =
350                 UnoRuntime.queryInterface(XAccessibleComponent.class, oObj);
351         System.out.println("BoundsX= "+accC.getBounds().X);
352         System.out.println("BoundsY= "+accC.getBounds().Y);
353         System.out.println("BoundsWidth= "+accC.getBounds().Width);
354         System.out.println("BoundsHeight= "+accC.getBounds().Height);
355 
356         accPC =
357                 UnoRuntime.queryInterface(XAccessibleComponent.class, parent);
358 
359         System.out.println("Parent-BoundsX= "+accPC.getBounds().X);
360         System.out.println("Parent-BoundsY= "+accPC.getBounds().Y);
361         System.out.println("Parent-BoundsWidth= "+accPC.getBounds().Width);
362         System.out.println("Parent-BoundsHeight= "+accPC.getBounds().Height);
363 
364         accPPC =
365         UnoRuntime.queryInterface(XAccessibleComponent.class,
366                         parent.getAccessibleContext().getAccessibleParent());
367 
368         System.out.println("P-Parent-BoundsX= "+accPPC.getBounds().X);
369         System.out.println("P-Parent-BoundsY= "+accPPC.getBounds().Y);
370         System.out.println("P-Parent-BoundsWidth= "+accPPC.getBounds().Width);
371         System.out.println("P-Parent-BoundsHeight= "+accPPC.getBounds().Height);
372 
373 
374 
375         System.out.println("Press any key when the footer is visible.");
376         try{
377             byte[]b = new byte[16];
378             System.in.read(b);
379         } catch (Exception e) {
380             e.printStackTrace();
381         }
382 
383         try {
384             parent = at.getAccessibleObjectForRole
385                 (xRoot, AccessibleRole.FOOTER, "").getAccessibleChild(0);
386         } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
387             fail(iabe.getMessage());
388             return;
389         }
390 
391         accPC =
392                 UnoRuntime.queryInterface(XAccessibleComponent.class, parent);
393 
394         try {
395             System.out.println("ChildCount: "+
396                     parent.getAccessibleContext().getAccessibleChildCount());
397             System.out.println("Getting child 0 again");
398             oObj = parent.getAccessibleContext().getAccessibleChild(0);
399         } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
400             fail(iabe.getMessage());
401             return;
402         }
403 
404         accT =
405                 UnoRuntime.queryInterface(XAccessibleText.class, oObj);
406         System.out.println("Getting the text: "+accT.getText());
407 
408         accC =
409                 UnoRuntime.queryInterface(XAccessibleComponent.class, oObj);
410         System.out.println("BoundsX= "+accC.getBounds().X);
411         System.out.println("BoundsY= "+accC.getBounds().Y);
412         System.out.println("BoundsWidth= "+accC.getBounds().Width);
413         System.out.println("BoundsHeight= "+accC.getBounds().Height);
414 
415         accPC =
416                 UnoRuntime.queryInterface(XAccessibleComponent.class, parent);
417 
418         System.out.println("Parent-BoundsX= "+accPC.getBounds().X);
419         System.out.println("Parent-BoundsY= "+accPC.getBounds().Y);
420         System.out.println("Parent-BoundsWidth= "+accPC.getBounds().Width);
421         System.out.println("Parent-BoundsHeight= "+accPC.getBounds().Height);
422 
423         accPPC =
424         UnoRuntime.queryInterface(XAccessibleComponent.class,
425                         parent.getAccessibleContext().getAccessibleParent());
426 
427         System.out.println("P-Parent-BoundsX= "+accPPC.getBounds().X);
428         System.out.println("P-Parent-BoundsY= "+accPPC.getBounds().Y);
429         System.out.println("P-Parent-BoundsWidth= "+accPPC.getBounds().Width);
430         System.out.println("P-Parent-BoundsHeight= "+accPPC.getBounds().Height);
431 
432 
433         System.out.println("Press any key when the page content is on top");
434         try{
435             byte[]b = new byte[16];
436             System.in.read(b);
437         } catch (Exception e) {
438             e.printStackTrace();
439         }
440 
441         try {
442             parent = at.getAccessibleObjectForRole
443                 (xRoot, AccessibleRole.DOCUMENT, "").getAccessibleChild(0);
444         } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
445             fail(iabe.getMessage());
446             return;
447         }
448         System.out.println("PARENT: " + parent.getAccessibleContext().getAccessibleName());
449         accPC =
450                 UnoRuntime.queryInterface(XAccessibleComponent.class, parent);
451 
452         int cCount = 0;
453         try {
454             cCount =
455                parent.getAccessibleContext().getAccessibleChildCount();
456             System.out.println("ChildCount: "+cCount);
457             System.out.println("Getting child 0 again");
458             oObj = parent.getAccessibleContext().getAccessibleChild(0);
459         } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
460             fail(iabe.getMessage());
461             return;
462         }
463 
464         for (int i=0; i<cCount; i++) {
465             try {
466                 XAccessible xA = parent.getAccessibleContext().getAccessibleChild(i);
467                 System.out.println("NAME object " + i + ": " + xA.getAccessibleContext().getAccessibleName());
468             } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
469                 fail(iabe.getMessage());
470                 return;
471             }
472         }
473 
474         System.out.println("SERVICES:");
475         util.dbg.getSuppServices(oObj);
476 
477         XAccessibleValue accV =
478                 UnoRuntime.queryInterface(XAccessibleValue.class, oObj);
479         Object o = accV.getCurrentValue();
480         if (o instanceof String)
481         {
482             System.out.println("Value: " + (String)o);
483         }
484         else
485         {
486             System.out.println("Name of Object: " + o.getClass().getName());
487         }
488         System.out.println("Getting the value: "+accV.getCurrentValue());
489 
490 
491 
492 
493         accC =
494                 UnoRuntime.queryInterface(XAccessibleComponent.class, oObj);
495         System.out.println("BoundsX= "+accC.getBounds().X);
496         System.out.println("BoundsY= "+accC.getBounds().Y);
497         System.out.println("BoundsWidth= "+accC.getBounds().Width);
498         System.out.println("BoundsHeight= "+accC.getBounds().Height);
499 
500         accPC =
501                 UnoRuntime.queryInterface(XAccessibleComponent.class, parent);
502 
503         System.out.println("Parent-BoundsX= "+accPC.getBounds().X);
504         System.out.println("Parent-BoundsY= "+accPC.getBounds().Y);
505         System.out.println("Parent-BoundsWidth= "+accPC.getBounds().Width);
506         System.out.println("Parent-BoundsHeight= "+accPC.getBounds().Height);
507 
508         accPPC =
509                 UnoRuntime.queryInterface(XAccessibleComponent.class,
510                         parent.getAccessibleContext().getAccessibleParent());
511 
512         System.out.println("P-Parent-BoundsX= "+accPPC.getBounds().X);
513         System.out.println("P-Parent-BoundsY= "+accPPC.getBounds().Y);
514         System.out.println("P-Parent-BoundsWidth= "+accPPC.getBounds().Width);
515         System.out.println("P-Parent-BoundsHeight= "+accPPC.getBounds().Height);
516 
517         XComponent xComp = UnoRuntime.queryInterface(
518                                     XComponent.class, xSpreadsheetDoc);
519         xComp.dispose();
520     }
521 
522 
523 
524 
525 
526 
527 
528 
529     /**
530      * Create a spreadsheet document, insert some text, header and footer.
531      * Let the user resize the document and check the contents.
532      */
533     @Test public void checkNegativeViewForwarder() {
534         SOfficeFactory SOF = SOfficeFactory.getFactory( mXMSF );
535         XSpreadsheetDocument xSpreadsheetDoc = null;
536 
537         try {
538             System.out.println("Creating a spreadsheet document");
539             xSpreadsheetDoc = SOF.createCalcDoc(null);
540         } catch (com.sun.star.uno.Exception e) {
541             fail(e.getMessage());
542             return;
543         }
544 
545         XInterface oObj = null;
546 
547         // inserting some content to have non-empty page preview
548         XCell xCell = null;
549         try {
550             XSpreadsheets oSheets = xSpreadsheetDoc.getSheets() ;
551             XIndexAccess oIndexSheets =
552                 UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
553             Object o = oIndexSheets.getByIndex(0);
554             XSpreadsheet oSheet = (XSpreadsheet)AnyConverter.toObject(
555                             new com.sun.star.uno.Type(XSpreadsheet.class), o);
556             xCell = oSheet.getCellByPosition(0, 0) ;
557             xCell.setFormula("ScAccessiblePageHeader");
558 
559             xCell = oSheet.getCellByPosition(0, 1) ;
560             xCell.setFormula("Cell 1");
561             xCell = oSheet.getCellByPosition(0, 2) ;
562             xCell.setFormula("Cell 2");
563         } catch(com.sun.star.lang.IllegalArgumentException e) {
564             System.out.println("Exception ceating relation :");
565             fail(e.getMessage());
566         } catch(com.sun.star.lang.WrappedTargetException e) {
567             System.out.println("Exception ceating relation :");
568             fail(e.getMessage());
569         } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
570             System.out.println("Exception ceating relation :");
571             fail(e.getMessage());
572         }
573 
574         XModel aModel =
575             UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc);
576 
577         XController xController = aModel.getCurrentController();
578 
579         // get page styles
580         XStyleFamiliesSupplier StyleFam =
581             UnoRuntime.queryInterface(
582                 XStyleFamiliesSupplier.class,
583                 xSpreadsheetDoc );
584         XNameAccess StyleFamNames = StyleFam.getStyleFamilies();
585         XStyle StdStyle = null;
586 
587         try{
588             Object o = StyleFamNames.getByName("PageStyles");
589             XNameAccess PageStyles = (XNameAccess)AnyConverter.toObject(
590                             new com.sun.star.uno.Type(XNameAccess.class), o);
591 
592             o = PageStyles.getByName("Default");
593             StdStyle = (XStyle)AnyConverter.toObject(
594                             new com.sun.star.uno.Type(XStyle.class), o);
595         } catch(com.sun.star.lang.IllegalArgumentException e) {
596             fail(e.getMessage());
597         } catch(com.sun.star.lang.WrappedTargetException e){
598             fail(e.getMessage());
599             return;
600         } catch(com.sun.star.container.NoSuchElementException e){
601             fail(e.getMessage());
602             return;
603         }
604 
605         //get the property-set
606         final XPropertySet PropSet =
607             UnoRuntime.queryInterface(XPropertySet.class, StdStyle);
608 
609         XHeaderFooterContent RPHFC = null;
610 
611         // get the header
612         System.out.println( "Creating a test environment" );
613         try {
614             Object o = PropSet.getPropertyValue("RightPageHeaderContent");
615             RPHFC = (XHeaderFooterContent)AnyConverter.toObject(
616                     new com.sun.star.uno.Type(XHeaderFooterContent.class), o);
617         } catch(com.sun.star.lang.IllegalArgumentException e) {
618             fail(e.getMessage());
619         } catch(com.sun.star.lang.WrappedTargetException e){
620             fail(e.getMessage());
621             return;
622         } catch(com.sun.star.beans.UnknownPropertyException e){
623             fail(e.getMessage());
624             return;
625         }
626 
627         // insert text into header
628         XText center = RPHFC.getCenterText();
629         center.setString("First line \n\r Second line \n\r third line ");
630         try {
631             PropSet.setPropertyValue("RightPageHeaderContent",RPHFC);
632         } catch (com.sun.star.beans.UnknownPropertyException e) {
633         } catch (com.sun.star.beans.PropertyVetoException e) {
634         } catch (com.sun.star.lang.IllegalArgumentException e) {
635         } catch (com.sun.star.lang.WrappedTargetException e) {}
636 
637         // get footer
638         RPHFC = null;
639         try {
640             Object o = PropSet.getPropertyValue("RightPageFooterContent");
641             RPHFC = (XHeaderFooterContent)AnyConverter.toObject(
642                     new com.sun.star.uno.Type(XHeaderFooterContent.class), o);
643         } catch(com.sun.star.lang.IllegalArgumentException e) {
644             fail(e.getMessage());
645         } catch(com.sun.star.lang.WrappedTargetException e){
646             fail(e.getMessage());
647             return;
648         } catch(com.sun.star.beans.UnknownPropertyException e){
649             fail(e.getMessage());
650             return;
651         }
652 
653         // insert text into footer
654         center = RPHFC.getCenterText();
655         center.setString("Third last line\n\r Second last line\n\r last line");
656         try {
657             PropSet.setPropertyValue("RightPageFooterContent",RPHFC);
658         } catch (com.sun.star.beans.UnknownPropertyException e) {
659         } catch (com.sun.star.beans.PropertyVetoException e) {
660         } catch (com.sun.star.lang.IllegalArgumentException e) {
661         } catch (com.sun.star.lang.WrappedTargetException e) {}
662 
663         // switching to 'Page Preview' mode
664         try {
665             XDispatchProvider xDispProv =
666                 UnoRuntime.queryInterface(XDispatchProvider.class, xController);
667             XURLTransformer xParser =
668                 UnoRuntime.queryInterface(XURLTransformer.class,
669             mXMSF.createInstance("com.sun.star.util.URLTransformer"));
670             // Because it's an in/out parameter we must use an
671             // array of URL objects.
672             URL[] aParseURL = new URL[1];
673             aParseURL[0] = new URL();
674             aParseURL[0].Complete = ".uno:PrintPreview";
675             xParser.parseStrict(aParseURL);
676             URL aURL = aParseURL[0];
677             XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0);
678             if(xDispatcher != null)
679             {
680                 xDispatcher.dispatch( aURL, null );
681             }
682         } catch (com.sun.star.uno.Exception e) {
683             fail("Couldn't change mode");
684             return;
685         }
686 
687         try {
688             Thread.sleep(500);
689         } catch (InterruptedException ex) {}
690 
691         System.out.println("Press any key after resizing ");
692         try{
693             byte[]b = new byte[16];
694             System.in.read(b);
695         } catch (Exception e) {
696             e.printStackTrace();
697         }
698 
699         // get the accessible content
700         AccessibilityTools at = new AccessibilityTools();
701 
702         XWindow xWindow = at.getCurrentWindow(mXMSF, aModel);
703         XAccessible xRoot = at.getAccessibleObject(xWindow);
704         XAccessible parent = null;
705 
706         try {
707             parent = at.getAccessibleObjectForRole
708                 (xRoot, AccessibleRole.HEADER, "").getAccessibleChild(0);
709             oObj = parent.getAccessibleContext().getAccessibleChild(0);
710         } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
711             fail(iabe.getMessage());
712             return;
713         }
714 
715         System.out.println("ImplementationName " + utils.getImplName(oObj));
716 
717         XAccessibleComponent accPC =
718                 UnoRuntime.queryInterface(XAccessibleComponent.class, parent);
719 
720         System.out.println("Parent-BoundsX= "+accPC.getBounds().X);
721         System.out.println("Parent-BoundsY= "+accPC.getBounds().Y);
722         System.out.println("Parent-BoundsWidth= "+accPC.getBounds().Width);
723         System.out.println("Parent-BoundsHeight= "+accPC.getBounds().Height);
724 
725         XAccessibleComponent accPPC =
726                         UnoRuntime.queryInterface(XAccessibleComponent.class,
727                         parent.getAccessibleContext().getAccessibleParent());
728 
729         System.out.println("P-Parent-BoundsX= "+accPPC.getBounds().X);
730         System.out.println("P-Parent-BoundsY= "+accPPC.getBounds().Y);
731         System.out.println("P-Parent-BoundsWidth= "+accPPC.getBounds().Width);
732         System.out.println("P-Parent-BoundsHeight= "+accPPC.getBounds().Height);
733 
734         try {
735             Thread.sleep(500);
736         } catch (InterruptedException ex) {}
737 
738         System.out.println("Press any key when the header is not visible.");
739         try{
740             byte[]b = new byte[16];
741             System.in.read(b);
742         } catch (Exception e) {
743             e.printStackTrace();
744         }
745 
746         int childCount = 0;
747         childCount =
748                 parent.getAccessibleContext().getAccessibleChildCount();
749         System.out.println("ChildCount: "+childCount);
750 
751         if (childCount != 0)
752         {
753             fail("Could access header although it was not visible on page.");
754         }
755 
756 
757         try {
758             parent = at.getAccessibleObjectForRole
759                 (xRoot, AccessibleRole.FOOTER, "").getAccessibleChild(0);
760         } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
761             fail(iabe.getMessage());
762             return;
763         }
764 
765         accPC =
766                 UnoRuntime.queryInterface(XAccessibleComponent.class, parent);
767 
768         System.out.println("Press any key when the footer is not visible.");
769         try{
770             byte[]b = new byte[16];
771             System.in.read(b);
772         } catch (Exception e) {
773             e.printStackTrace();
774         }
775 
776         childCount =
777                 parent.getAccessibleContext().getAccessibleChildCount();
778         System.out.println("ChildCount: "+childCount);
779 
780         if (childCount != 0)
781         {
782             fail("Could access footer although it was not visible on page.");
783         }
784 
785         XComponent xComp =UnoRuntime.queryInterface(
786                                         XComponent.class, xSpreadsheetDoc);
787         xComp.dispose();
788 
789     }
790 
791 
792 
793 
794     /**
795      * Check the preview of header cells
796      */
797     @Test public void checkPreviewHeaderCells() {
798 
799         XInterface oObj = null;
800         SOfficeFactory SOF = SOfficeFactory.getFactory( mXMSF);
801         XSpreadsheetDocument xSpreadsheetDoc = null;
802 
803         try {
804             System.out.println("Creating a spreadsheet document");
805             xSpreadsheetDoc = SOF.createCalcDoc(null);
806         } catch (com.sun.star.uno.Exception e) {
807             fail(e.getMessage());
808             return;
809         }
810 
811         XModel xModel =
812             UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc);
813 
814         XController xController = xModel.getCurrentController();
815 
816         //setting value of cell A1
817         XCell xCell = null;
818         try {
819             System.out.println("Getting spreadsheet") ;
820             XSpreadsheets oSheets = xSpreadsheetDoc.getSheets() ;
821             XIndexAccess oIndexSheets =
822             UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
823             Object o = oIndexSheets.getByIndex(0);
824             XSpreadsheet oSheet = (XSpreadsheet)AnyConverter.toObject(
825                             new com.sun.star.uno.Type(XSpreadsheet.class), o);
826 
827             System.out.println("Getting a cell from sheet") ;
828             xCell = oSheet.getCellByPosition(0, 0);
829         } catch(com.sun.star.lang.IllegalArgumentException e) {
830             fail(e.getMessage());
831         } catch (com.sun.star.lang.WrappedTargetException e) {
832             fail(e.getMessage());
833             return;
834         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
835             fail(e.getMessage());
836             return;
837         }
838 
839         xCell.setFormula("Value");
840 
841         //setting property 'PrintHeaders' of the style 'Default'
842         XStyleFamiliesSupplier xSFS =
843             UnoRuntime.queryInterface(XStyleFamiliesSupplier.class,
844                                                             xSpreadsheetDoc);
845         XNameAccess xNA = xSFS.getStyleFamilies();
846         XPropertySet xPropSet = null;
847         try {
848             Object oPageStyles = xNA.getByName("PageStyles");
849             xNA =
850                 UnoRuntime.queryInterface(XNameAccess.class, oPageStyles);
851             Object oDefStyle = xNA.getByName("Default");
852             xPropSet =
853                 UnoRuntime.queryInterface(XPropertySet.class, oDefStyle);
854         } catch(com.sun.star.lang.WrappedTargetException e) {
855             fail(e.getMessage());
856             return;
857         } catch(com.sun.star.container.NoSuchElementException e) {
858             fail(e.getMessage());
859             return;
860         }
861 
862         try {
863             xPropSet.setPropertyValue("PrintHeaders", new Boolean(true));
864         } catch(com.sun.star.lang.WrappedTargetException e) {
865             fail(e.getMessage());
866             return;
867         } catch(com.sun.star.lang.IllegalArgumentException e) {
868             fail(e.getMessage());
869             return;
870         } catch(com.sun.star.beans.PropertyVetoException e) {
871             fail(e.getMessage());
872             return;
873         } catch(com.sun.star.beans.UnknownPropertyException e) {
874             fail(e.getMessage());
875             return;
876         }
877 
878         //switching to 'Print Preview' mode
879         try {
880             XDispatchProvider xDispProv =
881                 UnoRuntime.queryInterface(XDispatchProvider.class, xController);
882             XURLTransformer xParser =
883                 UnoRuntime.queryInterface(XURLTransformer.class,
884             mXMSF.createInstance("com.sun.star.util.URLTransformer"));
885             URL[] aParseURL = new URL[1];
886             aParseURL[0] = new URL();
887             aParseURL[0].Complete = ".uno:PrintPreview";
888             xParser.parseStrict(aParseURL);
889             URL aURL = aParseURL[0];
890             XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0);
891             if(xDispatcher != null)
892             {
893                 xDispatcher.dispatch( aURL, null );
894             }
895         } catch (com.sun.star.uno.Exception e) {
896             fail(e.getMessage());
897             return;
898         }
899 
900         try {
901             Thread.currentThread().sleep(500) ;
902         } catch (InterruptedException e) {
903             System.out.println("While waiting :" + e) ;
904         }
905 
906         AccessibilityTools at = new AccessibilityTools();
907 
908         XWindow xWindow = at.getCurrentWindow(mXMSF, xModel);
909         XAccessible xRoot = at.getAccessibleObject(xWindow);
910 
911 //        System.out.println("ImplementationName " + utils.getImplName(oObj));
912 
913         System.out.println("Press any key when the header cell is on top.");
914         try{
915             byte[]b = new byte[16];
916             System.in.read(b);
917         } catch (Exception e) {
918             e.printStackTrace();
919         }
920 
921 
922         XAccessible parent = null;
923 
924         try {
925             System.out.println("Count: " +at.getAccessibleObjectForRole
926                 (xRoot, AccessibleRole.TABLE, "").getAccessibleChildCount());
927 //            parent = at.getAccessibleObjectForRole
928 //                (xRoot, AccessibleRole.TABLE, "").getAccessibleChild(0);
929 //            oObj = parent.getAccessibleContext().getAccessibleChild(1);
930             System.out.println("Getting child 2");
931             oObj = at.getAccessibleObjectForRole
932                 (xRoot, AccessibleRole.TABLE, "").getAccessibleChild(2);
933         } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
934             fail(iabe.getMessage());
935             return;
936         }
937 
938         System.out.println("*** DEBUG INFO ***");
939         util.dbg.getSuppServices(oObj);
940         System.out.println("****** IFC ******");
941         util.dbg.printInterfaces(oObj);
942         System.out.println("*****************");
943 
944 
945 /*        XAccessibleContext accCtx = (XAccessibleContext)
946                 UnoRuntime.queryInterface(XAccessibleContext.class, oObj);
947         try {
948             System.out.println("Children now: " + accCtx.getAccessibleChild(0).getAccessibleContext().getAccessibleChildCount());
949         } catch (com.sun.star.lang.IndexOutOfBoundsException iabe) {
950             fail(iabe.getMessage());
951             return;
952         }
953 */
954 
955         XAccessibleValue accV =
956                 UnoRuntime.queryInterface(XAccessibleValue.class, oObj);
957         Object o = accV.getCurrentValue();
958         System.out.println("Getting the value: "+o + " is void " + util.utils.isVoid(o));
959 
960 
961         XAccessibleComponent accC =
962                 UnoRuntime.queryInterface(XAccessibleComponent.class, oObj);
963 
964         System.out.println("BoundsX= "+accC.getBounds().X);
965         System.out.println("BoundsY= "+accC.getBounds().Y);
966         System.out.println("BoundsWidth= "+accC.getBounds().Width);
967         System.out.println("BoundsHeight= "+accC.getBounds().Height);
968 
969         XComponent xComp = UnoRuntime.queryInterface(
970                                         XComponent.class, xSpreadsheetDoc);
971         xComp.dispose();
972 
973     }
974 
975 
976 
977 
978 
979     /**
980      * Check the preview of Shapes: load a document with shapes and see, if they
981      * are accessible.
982      */
983     @Test public void checkPreviewShape() {
984         SOfficeFactory SOF = SOfficeFactory.getFactory( mXMSF );
985         XSpreadsheetDocument xSpreadsheetDoc = null;
986         XComponent xComp = null;
987         XInterface oObj = null;
988 
989         try {
990             String docName = "calcshapes.sxc";
991             System.out.println("Loading a spreadsheetdocument.");
992             // String url = utils.getFullURL((String)param.get("TestDocumentPath") + "/" + docName);
993             String url = TestDocument.getUrl(docName);
994             System.out.println("loading document '" + url + "'");
995             xComp = SOF.loadDocument(url);
996             assertNotNull(xComp);
997         }
998         catch (com.sun.star.uno.Exception e) {
999             fail(e.getMessage());
1000             return;
1001         }
1002 
1003         try {
1004             Thread.currentThread().sleep(500) ;
1005         } catch (InterruptedException e) {
1006             System.out.println("While waiting :" + e) ;
1007         }
1008 
1009         if (xComp == null) {
1010             fail("loading document failed.");
1011             return;
1012         }
1013 
1014         xSpreadsheetDoc = UnoRuntime.queryInterface(
1015                                             XSpreadsheetDocument.class, xComp);
1016         XModel aModel =
1017             UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc);
1018 
1019         XController xController = aModel.getCurrentController();
1020 
1021         // switching to 'Page Preview' mode
1022         try {
1023             XDispatchProvider xDispProv =
1024                 UnoRuntime.queryInterface(XDispatchProvider.class, xController);
1025             XURLTransformer xParser =
1026                 UnoRuntime.queryInterface(XURLTransformer.class,
1027             mXMSF.createInstance("com.sun.star.util.URLTransformer"));
1028             // Because it's an in/out parameter we must use an
1029             // array of URL objects.
1030             URL[] aParseURL = new URL[1];
1031             aParseURL[0] = new URL();
1032             aParseURL[0].Complete = ".uno:PrintPreview";
1033             xParser.parseStrict(aParseURL);
1034             URL aURL = aParseURL[0];
1035             XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0);
1036             if(xDispatcher != null)
1037             {
1038                 xDispatcher.dispatch( aURL, null );
1039             }
1040         } catch (com.sun.star.uno.Exception e) {
1041             fail("Couldn't change mode");
1042             return;
1043         }
1044 
1045         try {
1046             Thread.currentThread().sleep(500) ;
1047         } catch (InterruptedException e) {
1048             System.out.println("While waiting :" + e) ;
1049         }
1050 
1051 
1052 
1053         System.out.println("Press any key when a shape is on top.");
1054         try{
1055             byte[]b = new byte[16];
1056             System.in.read(b);
1057         } catch (Exception e) {
1058             e.printStackTrace();
1059         }
1060 
1061         // get the accessible content
1062         AccessibilityTools at = new AccessibilityTools();
1063 
1064         XWindow xWindow = at.getCurrentWindow(mXMSF, aModel);
1065         XAccessible xRoot = at.getAccessibleObject(xWindow);
1066         XAccessible parent = null;
1067 
1068         try {
1069             XAccessibleContext con = at.getAccessibleObjectForRole
1070                                 (xRoot, AccessibleRole.SHAPE, "");
1071             System.out.println("Name of AccessibleContext: " + con.getAccessibleName());
1072             oObj = con;
1073         } catch (Exception e) {
1074             fail(e.getMessage());
1075             return;
1076         }
1077 
1078         System.out.println("ImplementationName: " + utils.getImplName(oObj));
1079         util.dbg.printInterfaces(oObj);
1080 
1081         xComp.dispose();
1082     }
1083 
1084     @BeforeClass public static void setUpConnection() throws Exception {
1085         connection.setUp();
1086     }
1087 
1088     @AfterClass public static void tearDownConnection()
1089         throws InterruptedException, com.sun.star.uno.Exception
1090     {
1091         connection.tearDown();
1092     }
1093 
1094     private static final OfficeConnection connection = new OfficeConnection();
1095 
1096 }
1097 
1098 
1099