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