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 AccessibleOutlineView 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 Param test parameters
63      * @param log writer to log information while testing
64      *
65      * @see TestEnvironment
66      * @see #getTestEnvironment
67      */
createTestEnvironment(TestParameters Param, PrintWriter log)68     protected TestEnvironment createTestEnvironment
69             (TestParameters Param, PrintWriter log) {
70         XInterface oObj = null;
71 
72         AccessibilityTools at = new AccessibilityTools();
73 
74         XWindow xWindow = at.getCurrentWindow (
75                         (XMultiServiceFactory)Param.getMSF(),aModel);
76         XAccessible xRoot = at.getAccessibleObject(xWindow);
77 
78         at.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT);
79 
80         oObj = AccessibilityTools.SearchedContext;
81 
82         log.println("ImplementationName "+utils.getImplName(oObj));
83 
84         TestEnvironment tEnv = new TestEnvironment(oObj);
85 
86         XDrawPagesSupplier oDPS = (XDrawPagesSupplier)
87             UnoRuntime.queryInterface(XDrawPagesSupplier.class, aModel);
88         final XDrawPages oDPn = oDPS.getDrawPages();
89 
90         tEnv.addObjRelation("EventMsg","Inserting a drawpage via API has no "+
91                                         "effect to the outline view #101050# \r\n"+
92                                         "Therefore the listener isn't called");
93 
94         tEnv.addObjRelation("EventProducer",
95             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
96                 public void fireEvent() {
97                     oDPn.insertNewByIndex(1);
98                 }
99             });
100 
101         return tEnv;
102 
103     }
104 
105     /**
106     * Called while disposing a <code>TestEnvironment</code>.
107     * Disposes Impress documents.
108     * @param Param test parameters
109     * @param log writer to log information while testing
110     */
cleanup( TestParameters Param, PrintWriter log )111     protected void cleanup( TestParameters Param, PrintWriter log ) {
112         log.println("disposing Impress document");
113         util.DesktopTools.closeDoc(xImpressDoc);
114     }
115 
116     /**
117      * Called while the <code>TestCase</code> initialization. In the
118      * implementation does nothing. Subclasses can override to initialize
119      * objects shared among all <code>TestEnvironment</code>s.
120      *
121      * @param Param test parameters
122      * @param log writer to log information while testing
123      *
124      * @see #initializeTestCase
125      */
initialize(TestParameters Param, PrintWriter log)126     protected void initialize(TestParameters Param, PrintWriter log) {
127         // get a soffice factory object
128         SOfficeFactory SOF = SOfficeFactory.getFactory(
129                                 (XMultiServiceFactory)Param.getMSF());
130 
131         try {
132             log.println( "creating a impress document" );
133             xImpressDoc = SOF.createImpressDoc(null);
134             shortWait();
135         } catch (com.sun.star.uno.Exception e) {
136             e.printStackTrace( log );
137             throw new StatusException("Couldn't create document", e);
138         }
139 
140         aModel = (XModel)
141             UnoRuntime.queryInterface(XModel.class, xImpressDoc);
142 
143         XInterface oObj = aModel.getCurrentController();
144 
145         //Change to Outline view
146         try {
147             String aSlotID = "slot:27010";
148             XDispatchProvider xDispProv = (XDispatchProvider)
149                 UnoRuntime.queryInterface( XDispatchProvider.class, oObj );
150             XURLTransformer xParser = (com.sun.star.util.XURLTransformer)
151                 UnoRuntime.queryInterface(XURLTransformer.class,
152                 ((XMultiServiceFactory)Param.getMSF()).
153                 createInstance("com.sun.star.util.URLTransformer"));
154             // Because it's an in/out parameter we must use an array of URL objects.
155             URL[] aParseURL = new URL[1];
156             aParseURL[0] = new URL();
157             aParseURL[0].Complete = aSlotID;
158             xParser.parseStrict(aParseURL);
159             URL aURL = aParseURL[0];
160             XDispatch xDispatcher = xDispProv.queryDispatch( aURL,"",0);
161             if( xDispatcher != null )
162                     xDispatcher.dispatch( aURL, null );
163         } catch (com.sun.star.uno.Exception e) {
164             log.println("Couldn't change mode");
165         }
166         shortWait();
167     }
168 
shortWait()169     private void shortWait() {
170         try {
171             Thread.sleep(2000) ;
172         } catch (InterruptedException e) {
173             System.out.println("While waiting :" + e) ;
174         }
175     }
176 }
177 
178