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 mod._sd;
25 
26 import java.io.PrintWriter;
27 
28 import lib.StatusException;
29 import lib.TestCase;
30 import lib.TestEnvironment;
31 import lib.TestParameters;
32 import util.AccessibilityTools;
33 import util.SOfficeFactory;
34 import util.utils;
35 
36 import com.sun.star.accessibility.AccessibleRole;
37 import com.sun.star.accessibility.XAccessible;
38 import com.sun.star.awt.XWindow;
39 import com.sun.star.drawing.XDrawPages;
40 import com.sun.star.drawing.XDrawPagesSupplier;
41 import com.sun.star.frame.XDispatch;
42 import com.sun.star.frame.XDispatchProvider;
43 import com.sun.star.frame.XModel;
44 import com.sun.star.lang.XComponent;
45 import com.sun.star.lang.XMultiServiceFactory;
46 import com.sun.star.uno.UnoRuntime;
47 import com.sun.star.uno.XInterface;
48 import com.sun.star.util.URL;
49 import com.sun.star.util.XURLTransformer;
50 
51 public class AccessibleSlideView extends TestCase {
52 
53     XModel aModel = null;
54     XComponent xImpressDoc = null;
55 
56     /**
57      * Called to create an instance of <code>TestEnvironment</code> with an
58      * object to test and related objects. Subclasses should implement this
59      * method to provide the implementation and related objects. The method is
60      * called from <code>getTestEnvironment()</code>.
61      *
62      * @param tParam test parameters
63      * @param log writer to log information while testing
64      *
65      * @see TestEnvironment
66      * @see #getTestEnvironment()
67      */
68     protected TestEnvironment createTestEnvironment
69             (TestParameters Param, PrintWriter log) {
70         XInterface oObj = null;
71 
72         AccessibilityTools at = new AccessibilityTools();
73 
74         XDrawPagesSupplier oDPS = (XDrawPagesSupplier)
75             UnoRuntime.queryInterface(XDrawPagesSupplier.class, aModel);
76         XDrawPages oDPn = oDPS.getDrawPages();
77 
78 	oDPn.insertNewByIndex(0);
79 
80         shortWait();
81 
82         XWindow xWindow = at.getCurrentWindow (
83                                 (XMultiServiceFactory)Param.getMSF(),aModel);
84         XAccessible xRoot = at.getAccessibleObject(xWindow);
85 
86         at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
87 
88         at.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT);
89 
90         oObj = AccessibilityTools.SearchedContext;
91 
92         System.out.println("ImplementationName "+utils.getImplName(oObj));
93 
94         TestEnvironment tEnv = new TestEnvironment(oObj);
95 
96         //util.dbg.printInterfaces(oObj);
97         log.println("Implementationname: "+util.utils.getImplName(oObj));
98 
99         final XDrawPages DrawPages = oDPn;
100 
101         tEnv.addObjRelation("EventProducer",
102             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
103                 public void fireEvent() {
104                     DrawPages.insertNewByIndex(2);
105                 }
106             });
107 
108         return tEnv;
109 
110     }
111 
112     /**
113     * Called while disposing a <code>TestEnvironment</code>.
114     * Disposes Impress documents.
115     * @param tParam test parameters
116     * @param tEnv the environment to cleanup
117     * @param log writer to log information while testing
118     */
119     protected void cleanup( TestParameters Param, PrintWriter log ) {
120         log.println("disposing impress document");
121         util.DesktopTools.closeDoc(xImpressDoc);;
122     }
123 
124     /**
125      * Called while the <code>TestCase</code> initialization. In the
126      * implementation does nothing. Subclasses can override to initialize
127      * objects shared among all <code>TestEnvironment</code>s.
128      *
129      * @param tParam test parameters
130      * @param log writer to log information while testing
131      *
132      * @see #initializeTestCase()
133      */
134     protected void initialize(TestParameters Param, PrintWriter log) {
135         // get a soffice factory object
136         SOfficeFactory SOF = SOfficeFactory.getFactory(
137                                     (XMultiServiceFactory)Param.getMSF());
138 
139         try {
140             log.println( "creating a impress document" );
141             xImpressDoc = SOF.createImpressDoc(null);
142         } catch (com.sun.star.uno.Exception e) {
143             e.printStackTrace( log );
144             throw new StatusException("Couldn't create document", e);
145         }
146 
147         shortWait();
148 
149         aModel = (XModel)
150             UnoRuntime.queryInterface(XModel.class, xImpressDoc);
151 
152         //Change to Outline view
153         try {
154             String aSlotID = "slot:27011";
155             XDispatchProvider xDispProv = (XDispatchProvider)
156                 UnoRuntime.queryInterface( XDispatchProvider.class,
157                                         aModel.getCurrentController() );
158             XURLTransformer xParser = (com.sun.star.util.XURLTransformer)
159                 UnoRuntime.queryInterface(XURLTransformer.class,
160                 ((XMultiServiceFactory)Param.getMSF()).
161                 createInstance("com.sun.star.util.URLTransformer"));
162             // Because it's an in/out parameter we must use an array of URL objects.
163             URL[] aParseURL = new URL[1];
164             aParseURL[0] = new URL();
165             aParseURL[0].Complete = aSlotID;
166             xParser.parseStrict(aParseURL);
167             URL aURL = aParseURL[0];
168             XDispatch xDispatcher = xDispProv.queryDispatch( aURL,"",0);
169             if( xDispatcher != null )
170                     xDispatcher.dispatch( aURL, null );
171         } catch (com.sun.star.uno.Exception e) {
172             log.println("Couldn't change mode");
173         }
174 
175         shortWait();
176 
177     }
178 
179     private void shortWait() {
180         try {
181             Thread.sleep(2000) ;
182         } catch (InterruptedException e) {
183             System.out.println("While waiting :" + e) ;
184         }
185     }
186 }
187 
188