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 package mod._sch;
28 
29 import java.io.PrintWriter;
30 
31 import lib.StatusException;
32 import lib.TestCase;
33 import lib.TestEnvironment;
34 import lib.TestParameters;
35 import util.AccessibilityTools;
36 import util.SOfficeFactory;
37 import util.utils;
38 
39 import com.sun.star.accessibility.AccessibleRole;
40 import com.sun.star.accessibility.XAccessible;
41 import com.sun.star.accessibility.XAccessibleComponent;
42 import com.sun.star.accessibility.XAccessibleContext;
43 import com.sun.star.awt.XWindow;
44 import com.sun.star.chart.XChartDocument;
45 import com.sun.star.frame.XModel;
46 import com.sun.star.lang.XMultiServiceFactory;
47 import com.sun.star.uno.UnoRuntime;
48 import com.sun.star.uno.XInterface;
49 
50 public class AccAxis extends TestCase {
51 
52     XChartDocument xChartDoc = null;
53 
54     protected TestEnvironment createTestEnvironment(
55         TestParameters Param, PrintWriter log) {
56 
57         if (xChartDoc != null) cleanup(Param, log);
58         log.println( "creating a chart document" );
59         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
60         try {
61             log.println( "creating a chartdocument" );
62             xChartDoc = SOF.createChartDoc(null);
63         } catch (com.sun.star.uno.Exception e) {
64             // Some exception occures.FAILED
65             e.printStackTrace( log );
66             throw new StatusException( "Couldn't create document", e );
67         }
68 
69         XInterface oObj = null;
70 
71         XModel aModel = (XModel)
72             UnoRuntime.queryInterface(XModel.class, xChartDoc);
73 
74         AccessibilityTools at = new AccessibilityTools();
75 
76         XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
77         XAccessible xRoot = at.getAccessibleObject(xWindow);
78 
79         XAccessibleContext cont = at.getAccessibleObjectForRole(
80                 xRoot, AccessibleRole.SHAPE, "", "AccAxis");
81 
82 
83         oObj = cont;
84 
85         log.println("ImplementationName " + utils.getImplName(oObj));
86         log.println("AccessibleName " + cont.getAccessibleName());
87 
88         TestEnvironment tEnv = new TestEnvironment(oObj);
89 
90         final XAccessibleComponent acc = (XAccessibleComponent)
91                 UnoRuntime.queryInterface(
92                     XAccessibleComponent.class,oObj);
93         tEnv.addObjRelation("EventProducer",
94             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
95                 public void fireEvent() {
96                         acc.grabFocus();
97                 }
98             });
99 
100         return tEnv;
101 
102     }
103 
104     /**
105     * Called while disposing a <code>TestEnvironment</code>.
106     * Disposes text document.
107     * @param tParam test parameters
108     * @param tEnv the environment to cleanup
109     * @param log writer to log information while testing
110     */
111     protected void cleanup( TestParameters Param, PrintWriter log) {
112         if( xChartDoc!=null ) {
113             log.println( "    closing xChartDoc" );
114             util.DesktopTools.closeDoc(xChartDoc);
115             xChartDoc = null;
116         }
117     }
118 
119 }
120