xref: /AOO41X/main/qadevOOo/tests/java/mod/_sd/AccessibleSlideView.java (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package mod._sd;
29 
30 import java.io.PrintWriter;
31 
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.AccessibilityTools;
37 import util.SOfficeFactory;
38 import util.utils;
39 
40 import com.sun.star.accessibility.AccessibleRole;
41 import com.sun.star.accessibility.XAccessible;
42 import com.sun.star.awt.XWindow;
43 import com.sun.star.drawing.XDrawPages;
44 import com.sun.star.drawing.XDrawPagesSupplier;
45 import com.sun.star.frame.XDispatch;
46 import com.sun.star.frame.XDispatchProvider;
47 import com.sun.star.frame.XModel;
48 import com.sun.star.lang.XComponent;
49 import com.sun.star.lang.XMultiServiceFactory;
50 import com.sun.star.uno.UnoRuntime;
51 import com.sun.star.uno.XInterface;
52 import com.sun.star.util.URL;
53 import com.sun.star.util.XURLTransformer;
54 
55 public class AccessibleSlideView extends TestCase {
56 
57     XModel aModel = null;
58     XComponent xImpressDoc = null;
59 
60     /**
61      * Called to create an instance of <code>TestEnvironment</code> with an
62      * object to test and related objects. Subclasses should implement this
63      * method to provide the implementation and related objects. The method is
64      * called from <code>getTestEnvironment()</code>.
65      *
66      * @param tParam test parameters
67      * @param log writer to log information while testing
68      *
69      * @see TestEnvironment
70      * @see #getTestEnvironment()
71      */
72     protected TestEnvironment createTestEnvironment
73             (TestParameters Param, PrintWriter log) {
74         XInterface oObj = null;
75 
76         AccessibilityTools at = new AccessibilityTools();
77 
78         XDrawPagesSupplier oDPS = (XDrawPagesSupplier)
79             UnoRuntime.queryInterface(XDrawPagesSupplier.class, aModel);
80         XDrawPages oDPn = oDPS.getDrawPages();
81 
82 	oDPn.insertNewByIndex(0);
83 
84         shortWait();
85 
86         XWindow xWindow = at.getCurrentWindow (
87                                 (XMultiServiceFactory)Param.getMSF(),aModel);
88         XAccessible xRoot = at.getAccessibleObject(xWindow);
89 
90         at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
91 
92         at.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT);
93 
94         oObj = AccessibilityTools.SearchedContext;
95 
96         System.out.println("ImplementationName "+utils.getImplName(oObj));
97 
98         TestEnvironment tEnv = new TestEnvironment(oObj);
99 
100         //util.dbg.printInterfaces(oObj);
101         log.println("Implementationname: "+util.utils.getImplName(oObj));
102 
103         final XDrawPages DrawPages = oDPn;
104 
105         tEnv.addObjRelation("EventProducer",
106             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
107                 public void fireEvent() {
108                     DrawPages.insertNewByIndex(2);
109                 }
110             });
111 
112         return tEnv;
113 
114     }
115 
116     /**
117     * Called while disposing a <code>TestEnvironment</code>.
118     * Disposes Impress documents.
119     * @param tParam test parameters
120     * @param tEnv the environment to cleanup
121     * @param log writer to log information while testing
122     */
123     protected void cleanup( TestParameters Param, PrintWriter log ) {
124         log.println("disposing impress document");
125         util.DesktopTools.closeDoc(xImpressDoc);;
126     }
127 
128     /**
129      * Called while the <code>TestCase</code> initialization. In the
130      * implementation does nothing. Subclasses can override to initialize
131      * objects shared among all <code>TestEnvironment</code>s.
132      *
133      * @param tParam test parameters
134      * @param log writer to log information while testing
135      *
136      * @see #initializeTestCase()
137      */
138     protected void initialize(TestParameters Param, PrintWriter log) {
139         // get a soffice factory object
140         SOfficeFactory SOF = SOfficeFactory.getFactory(
141                                     (XMultiServiceFactory)Param.getMSF());
142 
143         try {
144             log.println( "creating a impress document" );
145             xImpressDoc = SOF.createImpressDoc(null);
146         } catch (com.sun.star.uno.Exception e) {
147             e.printStackTrace( log );
148             throw new StatusException("Couldn't create document", e);
149         }
150 
151         shortWait();
152 
153         aModel = (XModel)
154             UnoRuntime.queryInterface(XModel.class, xImpressDoc);
155 
156         //Change to Outline view
157         try {
158             String aSlotID = "slot:27011";
159             XDispatchProvider xDispProv = (XDispatchProvider)
160                 UnoRuntime.queryInterface( XDispatchProvider.class,
161                                         aModel.getCurrentController() );
162             XURLTransformer xParser = (com.sun.star.util.XURLTransformer)
163                 UnoRuntime.queryInterface(XURLTransformer.class,
164                 ((XMultiServiceFactory)Param.getMSF()).
165                 createInstance("com.sun.star.util.URLTransformer"));
166             // Because it's an in/out parameter we must use an array of URL objects.
167             URL[] aParseURL = new URL[1];
168             aParseURL[0] = new URL();
169             aParseURL[0].Complete = aSlotID;
170             xParser.parseStrict(aParseURL);
171             URL aURL = aParseURL[0];
172             XDispatch xDispatcher = xDispProv.queryDispatch( aURL,"",0);
173             if( xDispatcher != null )
174                     xDispatcher.dispatch( aURL, null );
175         } catch (com.sun.star.uno.Exception e) {
176             log.println("Couldn't change mode");
177         }
178 
179         shortWait();
180 
181     }
182 
183     private void shortWait() {
184         try {
185             Thread.sleep(2000) ;
186         } catch (InterruptedException e) {
187             System.out.println("While waiting :" + e) ;
188         }
189     }
190 }
191 
192