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._sw;
28 
29 import java.io.PrintWriter;
30 
31 import lib.TestCase;
32 import lib.TestEnvironment;
33 import lib.TestParameters;
34 import util.AccessibilityTools;
35 import util.WriterTools;
36 import util.utils;
37 
38 import com.sun.star.accessibility.AccessibleRole;
39 import com.sun.star.accessibility.XAccessible;
40 import com.sun.star.awt.XWindow;
41 import com.sun.star.frame.XModel;
42 import com.sun.star.lang.XMultiServiceFactory;
43 import com.sun.star.text.XText;
44 import com.sun.star.text.XTextDocument;
45 import com.sun.star.uno.UnoRuntime;
46 import com.sun.star.uno.XInterface;
47 
48 /**
49 * Test of accessible object for paragraph of a text document.<p>
50 * Object implements the following interfaces :
51 * <ul>
52 *  <li> <code>::com::sun::star::accessibility::XAccessible</code></li>
53 * </ul>
54 * @see com.sun.star.accessibility.XAccessible
55 */
56 public class SwAccessibleParagraphView extends TestCase {
57 
58     XTextDocument xTextDoc = null;
59 
60     /**
61     * Called to create an instance of <code>TestEnvironment</code>
62     * with an object to test and related objects. Obtains accessible object
63     * for one of document paragraph.
64     *
65     * @param tParam test parameters
66     * @param log writer to log information while testing
67     *
68     * @see TestEnvironment
69     * @see #getTestEnvironment()
70     */
71     protected TestEnvironment createTestEnvironment(
72         TestParameters Param, PrintWriter log) {
73 
74         XInterface oObj = null;
75 
76         XText oText = xTextDoc.getText();
77         oText.setString("XAccessibleText");
78 
79         XModel aModel = (XModel)
80             UnoRuntime.queryInterface(XModel.class, xTextDoc);
81 
82         AccessibilityTools at = new AccessibilityTools();
83 
84         XWindow xWindow = at.getCurrentWindow( (XMultiServiceFactory) Param.getMSF(), aModel);
85         XAccessible xRoot = at.getAccessibleObject(xWindow);
86 
87         at.getAccessibleObjectForRole(xRoot, AccessibleRole.PARAGRAPH);
88 
89         oObj = at.SearchedContext;
90 
91         log.println("ImplementationName " + utils.getImplName(oObj));
92 
93         TestEnvironment tEnv = new TestEnvironment(oObj);
94 
95         final XText paraText = xTextDoc.getText();
96 
97         tEnv.addObjRelation("EventProducer",
98             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
99                 public void fireEvent() {
100                     String old = paraText.getString();
101                     paraText.setString("Just a line");
102                     paraText.setString(old);
103                 }
104             });
105 
106         final String text = "XAccessibleText";
107 
108         tEnv.addObjRelation("XAccessibleText.Text", text);
109 
110         return tEnv;
111 
112     }
113 
114     /**
115     * Called while disposing a <code>TestEnvironment</code>.
116     * Disposes text document.
117     * @param tParam test parameters
118     * @param tEnv the environment to cleanup
119     * @param log writer to log information while testing
120     */
121     protected void cleanup( TestParameters Param, PrintWriter log) {
122         log.println("dispose text document");
123         util.DesktopTools.closeDoc(xTextDoc);
124     }
125 
126     /**
127      * Called while the <code>TestCase</code> initialization.
128      * Creates a text document.
129      *
130      * @param tParam test parameters
131      * @param log writer to log information while testing
132      *
133      * @see #initializeTestCase()
134      */
135     protected void initialize(TestParameters Param, PrintWriter log) {
136         log.println( "creating a text document" );
137         xTextDoc = WriterTools.createTextDoc( (XMultiServiceFactory) Param.getMSF());
138     }
139 }
140