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 package mod._sw;
24 
25 import java.io.PrintWriter;
26 
27 import lib.StatusException;
28 import lib.TestCase;
29 import lib.TestEnvironment;
30 import lib.TestParameters;
31 import util.AccessibilityTools;
32 import util.WriterTools;
33 import util.utils;
34 
35 import com.sun.star.accessibility.AccessibleRole;
36 import com.sun.star.accessibility.XAccessible;
37 import com.sun.star.awt.XWindow;
38 import com.sun.star.beans.XPropertySet;
39 import com.sun.star.container.XNameAccess;
40 import com.sun.star.frame.XController;
41 import com.sun.star.frame.XModel;
42 import com.sun.star.lang.XMultiServiceFactory;
43 import com.sun.star.style.XStyle;
44 import com.sun.star.style.XStyleFamiliesSupplier;
45 import com.sun.star.text.XTextDocument;
46 import com.sun.star.uno.AnyConverter;
47 import com.sun.star.uno.Type;
48 import com.sun.star.uno.UnoRuntime;
49 import com.sun.star.uno.XInterface;
50 import com.sun.star.view.XViewSettingsSupplier;
51 
52 /**
53 * Test of accessible object for a footer of a text document.<p>
54 * Object implements the following interfaces :
55 * <ul>
56 *  <li> <code>::com::sun::star::accessibility::XAccessible</code></li>
57 * </ul>
58 * @see com.sun.star.accessibility.XAccessible
59 */
60 public class SwAccessibleFooterView extends TestCase {
61 
62     XTextDocument xTextDoc = null;
63 
64     /**
65     * Called to create an instance of <code>TestEnvironment</code>
66     * with an object to test and related objects. Obtains style
67     * <code>Standard</code> from style family <code>PageStyles</code>.
68     * Changes values of property <code>FooterIsOn</code> by <code>true</code>.
69     * Changes zoom value to 10%(footer must be in visible area of the document).
70     * Obtains accessible component for the footer.
71     *
72     * @param Param test parameters
73     * @param log writer to log information while testing
74     *
75     * @see TestEnvironment
76     * @see #getTestEnvironment
77     */
createTestEnvironment( TestParameters Param, PrintWriter log)78     protected TestEnvironment createTestEnvironment(
79         TestParameters Param, PrintWriter log) {
80 
81         XInterface oObj = null;
82         XNameAccess PageStyles = null;
83         XStyle StdStyle = null;
84 
85         XStyleFamiliesSupplier StyleFam = (XStyleFamiliesSupplier)
86             UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, xTextDoc);
87         XNameAccess StyleFamNames = StyleFam.getStyleFamilies();
88 
89         // obtains style 'Standard' from style family 'PageStyles'
90         try {
91             PageStyles = (XNameAccess) AnyConverter.toObject(
92                 new Type(XNameAccess.class),StyleFamNames.getByName("PageStyles"));
93             StdStyle = (XStyle) AnyConverter.toObject(
94                     new Type(XStyle.class),PageStyles.getByName("Standard"));
95         } catch ( com.sun.star.lang.WrappedTargetException e ) {
96             e.printStackTrace(log);
97             throw new StatusException("Error getting style by name!", e);
98         } catch ( com.sun.star.container.NoSuchElementException e ) {
99             e.printStackTrace(log);
100             throw new StatusException("Error, no such style name! ", e);
101         } catch ( com.sun.star.lang.IllegalArgumentException e ) {
102             e.printStackTrace(log);
103             throw new StatusException("Error getting style by name!", e);
104         }
105 
106         final XPropertySet PropSet = (XPropertySet)
107             UnoRuntime.queryInterface( XPropertySet.class, StdStyle);
108 
109         // changing/getting some properties
110         try {
111             log.println( "Switching on footer" );
112             PropSet.setPropertyValue("FooterIsOn", new Boolean(true));
113 
114             //change zoom value to 10%
115             //footer should be in the vissible area of the document
116             XController xController = xTextDoc.getCurrentController();
117             XViewSettingsSupplier xViewSetSup = (XViewSettingsSupplier)
118                 UnoRuntime.queryInterface(XViewSettingsSupplier.class,
119                 xController);
120             XPropertySet xPropSet = xViewSetSup.getViewSettings();
121             xPropSet.setPropertyValue("ZoomValue", new Short("20"));
122         } catch ( com.sun.star.lang.WrappedTargetException e ) {
123             e.printStackTrace(log);
124             throw new StatusException("Couldn't set propertyValue...", e);
125         }  catch ( com.sun.star.lang.IllegalArgumentException e ) {
126             e.printStackTrace(log);
127             throw new StatusException("Couldn't set propertyValue...", e);
128         } catch ( com.sun.star.beans.PropertyVetoException e ) {
129             e.printStackTrace(log);
130             throw new StatusException("Couldn't set propertyValue...", e);
131         } catch ( com.sun.star.beans.UnknownPropertyException e ) {
132             e.printStackTrace(log);
133             throw new StatusException("Couldn't set propertyValue...", e);
134         }
135 
136         XModel aModel = (XModel)
137             UnoRuntime.queryInterface(XModel.class, xTextDoc);
138 
139         AccessibilityTools at = new AccessibilityTools();
140 
141         XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
142         XAccessible xRoot = at.getAccessibleObject(xWindow);
143 
144         at.getAccessibleObjectForRole(xRoot, AccessibleRole.FOOTER);
145 
146         oObj = AccessibilityTools.SearchedContext;
147 
148         log.println("ImplementationName " + utils.getImplName(oObj));
149         at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
150 
151         TestEnvironment tEnv = new TestEnvironment(oObj);
152 
153         tEnv.addObjRelation("EventProducer",
154             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
155                 public void fireEvent() {
156                     try {
157                         PropSet.setPropertyValue("FooterLeftMargin",
158                             new Integer(1000));
159                     } catch (com.sun.star.uno.Exception e) {
160                         e.printStackTrace();
161                         throw new StatusException("Cann't change footer.", e);
162                     }
163                 }
164             });
165 
166         return tEnv;
167 
168     }
169 
170     /**
171     * Called while disposing a <code>TestEnvironment</code>.
172     * Disposes text document.
173     * @param Param test parameters
174     * @param log writer to log information while testing
175     */
cleanup( TestParameters Param, PrintWriter log)176     protected void cleanup( TestParameters Param, PrintWriter log) {
177         log.println("dispose text document");
178         util.DesktopTools.closeDoc(xTextDoc);
179     }
180 
181     /**
182      * Called while the <code>TestCase</code> initialization.
183      * Creates a text document.
184      *
185      * @param Param test parameters
186      * @param log writer to log information while testing
187      *
188      * @see #initializeTestCase
189      */
initialize(TestParameters Param, PrintWriter log)190     protected void initialize(TestParameters Param, PrintWriter log) {
191         log.println( "creating a text document" );
192         xTextDoc = WriterTools.createTextDoc((XMultiServiceFactory)Param.getMSF());
193     }
194 
195 }
196